Skip to content

Instantly share code, notes, and snippets.

@george-hawkins
Created March 1, 2018 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save george-hawkins/9ca65b1d9fb0e36b88ac79dd48307808 to your computer and use it in GitHub Desktop.
Save george-hawkins/9ca65b1d9fb0e36b88ac79dd48307808 to your computer and use it in GitHub Desktop.
Setup PS1 prompt
if [[ -n $SSH_CLIENT || -n $SSH_TTY ]]
then
PS1_HOST='\h'
else
PS1_HOST=localhost
fi
# Usually people use raw escape sequences for colors but you can lookup these sequences with tput.
BOLD=$(tput bold)
GREEN=$(tput setaf 2)
BLUE=$(tput setaf 4)
RESET="$(tput sgr0)"
# '\[...\]' - tell Bash that a sequence is non-printing (so it can calculate length correctly).
# \e = ESC, \a = BEL
# \u = username, \h = hostname, \w = CWD
PS1="\[${BOLD}${GREEN}\]\u@${PS1_HOST}${RESET}:\[${BOLD}${BLUE}\]\w\[${RESET}\]\$ "
case "$TERM" in
xterm*|rxvt*)
# Set window title to string xyz - '\e]0;xyz\a' - http://tldp.org/HOWTO/Xterm-Title-3.html
PS1="\[\e]0;\u@${PS1_HOST}: \w\a\]$PS1"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment