Will give prompts of the form
host ~/working/dir $
when outside a Git repo, and of the form
host repository_name/path/from/repo/root (branch) $
when inside one.
Joyful colors included.
PS1='\[\e[1;32m\]\h `if git status > /dev/null 2>&1; \ | |
then GITTOP=\`git rev-parse --show-toplevel\`; \ | |
echo -e "\[\e[1;36m\]"\ | |
\`basename $GITTOP\`\ | |
"\[\e[1;33m\]"\ | |
\/\`realpath --relative-to=$GITTOP .\` \ | |
"\[\e[1;34m\]"\ | |
\(\`git rev-parse --abbrev-ref HEAD 2> /dev/null\`\) ; \ | |
else echo -e "\[\e[1;34m\]""\w"; fi` \$ \[\e[0m\]' |