Created
March 1, 2018 10:06
-
-
Save george-hawkins/9ca65b1d9fb0e36b88ac79dd48307808 to your computer and use it in GitHub Desktop.
Setup PS1 prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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