Skip to content Skip to navigation

Improving the SSH Command Line Experience with Bash

Posted by: 
Topics: 

Problem:

Working on the command line on the Leland AFS space is primitive. By using the bash shell and a few tweaks, the usability of the command line greatly improves.

Solution
Step 1: Edit the bashrc file. vim ~/.bashrc. You can use pico or any of your favorite editors.
Step 2: Paste the text below into the ~/.bashrc file. Copy the text below. In VI type "i" for insert mode and then ctrl-insert to paste.
Step 3: Save and quit the file. In VI type :wq

Now type "bash" to load your new bash shell. If you copied and pasted correctly, you should see your prompt change into a green and purple color.

Remember each time you log into the command line, you will need to type "bash" to load the bash Shell.

-------------------------------

# Define some colors first:
red='\033[0;31m'
RED='\033[1;31m'
green='\033[0;32m'
GREEN='\033[1;32m'
blue='\033[0;34m'
BLUE='\033[1;34m'
purple='\033[0;35m'
PURPLE='\033[1;35m'
cyan='\033[0;36m'
CYAN='\033[1;36m'
NC='\033[0m' # No Color

# If id command returns zero, you’ve root access.
if [ $(id -u) -eq 0 ];
then # you are root, set the prompt to #
#Display Full Path with Color
export PS1="\[${GREEN}\]\u\[${NC}\]@\[${PURPLE}\]\h\[${NC}\]:\[${CYAN}\]\w\[${NC}\]# "
else # normal. The prompt is $
export PS1="\[${GREEN}\]\u\[${NC}\]@\[${PURPLE}\]\h\[${NC}\]:\[${CYAN}\]\w\[${NC}\]$ "
fi

alias vi='vim'

#Improving how ls works
alias ls='ls -aF --color=always'
alias ll='ls -l'

#Cleans bash history. Does not include lines starting with spaces
#and duplicate lines
export HISTCONTROL=ignoreboth

#Correct misspellings of directories.
shopt -s cdspell

#allows files beginning with a dot to be returned in filename expansions.
shopt -s dotglob

#Change the title of Xterm
case $TERM in
xterm*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}:${PWD}\007"'
;;
*)
;;
esac