Skip to content

Instantly share code, notes, and snippets.

@marciomazza
Created June 16, 2012 14:49
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 marciomazza/2941527 to your computer and use it in GitHub Desktop.
Save marciomazza/2941527 to your computer and use it in GitHub Desktop.
Colorize the last portion of directory name in your shell prompt
function short_pwd () {
pwd | sed -e "s@$HOME@~@"
}
function ps1_dir () {
dn=$(dirname `short_pwd`)
# in ~ yields "./" that becomes ""
# in / yields "//" that becomes "/"
echo "$dn/" | sed -e 's@^\./$@@' | sed -e 's@^//$@/@'
}
function ps1_base() {
# in ~ yields "~"
# in / yields "/" that becomes ""
basename `short_pwd` | sed -e 's@^/$@@'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
NO_COLOUR="\[\033[0m\]"
PS1="$GREEN\$(ps1_dir)$YELLOW\$(ps1_base)$NO_COLOUR "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment