Skip to content

Instantly share code, notes, and snippets.

@typingincolor
Last active October 29, 2015 15:54
Show Gist options
  • Save typingincolor/0a7c422663f50be293f2 to your computer and use it in GitHub Desktop.
Save typingincolor/0a7c422663f50be293f2 to your computer and use it in GitHub Desktop.
Terminal Prompt Magic
function __git_branch() {
b=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ ! -z "$b" ]; then
echo "($b) "
else
echo ""
fi
}
function __git_dirty() {
if [ ! -z "$(git status --porcelain 2>/dev/null)" ]; then
echo "* "
else
echo ""
fi
}
function __pwd() {
pwd_length=20
# horizontal ellipsis
pwd_symbol=$(echo $'\xe2\x80\xa6')
newPWD="${PWD/#$HOME/~}"
if [ $(echo -n $newPWD | wc -c | tr -d " ") -gt $pwd_length ]
then
newPWD=$(echo -n $newPWD | awk -v pwd_symbol="$pwd_symbol" -F '/' '{print $1 "/" $2 "/" pwd_symbol "/" $(NF-1) "/" $(NF)}')
fi
echo $newPWD
}
# ╥☺
custom=$(echo $'\xe2\x95\xa5\xe2\x98\xba')
# colours
bg_yellow="\[\e[43m\]"
bg_light_gray="\[\e[47m\]"
fg_red="\[\e[31m\]"
fg_bold_yellow="\[\e[1;32m\]"
fg_reset="\[\e[0m\]"
export PS1="$bg_yellow$fg_red\t$fg_reset $fg_red\$(__git_branch)\$(__git_dirty) $fg_bold_yellow\$(__pwd)$fg_reset\n$fg_reset$bg_light_gray$fg_red$custom$fg_reset "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment