Created
June 16, 2012 14:49
-
-
Save marciomazza/2941527 to your computer and use it in GitHub Desktop.
Colorize the last portion of directory name in your shell prompt
This file contains hidden or 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
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