Skip to content

Instantly share code, notes, and snippets.

@nad2000
Last active January 1, 2016 14:19
Show Gist options
  • Save nad2000/8157072 to your computer and use it in GitHub Desktop.
Save nad2000/8157072 to your computer and use it in GitHub Desktop.
Setup git BASH environment: prompt with the current branch and status color code (GREEN - no changes; RED - something to commit; YELLOW - something else: a new un-tracked file etc.), current directory shortening. #git #bash #nad2000
# drops first portion of a path $1 if length is greater than $2
function __droppath {
if [[ ${#1} -gt $2 ]]; then
p=$1
while [ ${#p} -gt $2 ]; do
p="/"$(echo "$p"|cut -d"/" -f3-)
done
echo "..."$p
else
echo $1
fi
}
export PS1='${debian_chroot:+($debian_chroot)}\[\e[01;30m\]\[\e[00;37m\]\u\[\e[01;37m\]:`case $(git status 2> /dev/null | sed -n '2p') in "nothing to commit, working directory clean") echo "\[\e[32m\]";; "# Changes to be committed:") echo "\[\e[31m\]";; *) echo "\[\e[33m\]";; esac`$(__git_ps1 "(%s)\[\e[00m\]")\[\e[01;34m\]$(__droppath "\w" 20)\[\e[00m\]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment