Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[sh] show current branch in bash-prompt
#!/bin/bash
## git bash-prompt
GIT_THEME_PROMPT_DIRTY='*'
function git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo -e "(${ref#refs/heads/}$(parse_git_dirty))"
}
function parse_git_dirty {
if [[ -n $(git status -s 2> /dev/null |grep -v ^# | grep -v "working directory clean" ) ]]; then
echo -e "$GIT_THEME_PROMPT_DIRTY"
else
echo -e "$GIT_THEME_PROMPT_CLEAN"
fi
}
# Tell ls to be colourful
export CLICOLOR=1
export LSCOLORS=Exfxcxdxbxegedabagacad
PS1="\[\033[1;33m\]\W\[\033[0m\] \[\033[1;32m\]\[\$(git_prompt_info)\]\[\033[0m\]$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.