Skip to content

Instantly share code, notes, and snippets.

@jtwb
Created June 28, 2012 21:49
Show Gist options
  • Save jtwb/3014185 to your computer and use it in GitHub Desktop.
Save jtwb/3014185 to your computer and use it in GitHub Desktop.
Sexy PS1 with collapsed git branch name and dirs stack
function dirs_depth () {
echo `dirs -v | wc -l`
}
function parse_git_branch () {
BRANCH=$(git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
BLEN=$(echo `echo $BRANCH | wc -c` " - 1" | bc)
echo $BRANCH | cut -c1 | sed -e "s/^./${BLEN}\0/"
}
function extra_color () {
NUM=;
let "NUM = $RANDOM % 100";
if [ $NUM -lt 30 ]
then
echo -e "\033[34m"
fi
}
PS1='\[\e[0;31m\]$(dirs_depth)\[\e[0;32m\]\u$(extra_color)@\[\e[0;32m\]\h\[\e[0m\]\[\e[0;33m\]$(parse_git_branch)\[\e[0m\]:\w\$ '
@jtwb
Copy link
Author

jtwb commented Jun 28, 2012

Example, sans color:
7j@ubuntu6m:~/src$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment