Skip to content

Instantly share code, notes, and snippets.

@hacst
Created January 15, 2013 12:30
Show Gist options
  • Save hacst/4538282 to your computer and use it in GitHub Desktop.
Save hacst/4538282 to your computer and use it in GitHub Desktop.
Custom dash prompt which displays current branch and dirty status in the prompt line when in a git repository folder. Add to .bashrc or another file executed by it like .bash_aliases.
RS="\033[0m" # reset
HC="\033[1m" # hicolor
INV="\033[7m" # inverse background and foreground
function git_dirty() {
if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
echo -n "\[$INV\]*"
else
echo -n "\[$HC\]"
fi
}
function get_git_branch() {
local br=$(git branch 2> /dev/null | grep "*" | sed 's/* //g')
[ -n "$br" ] && echo ":$(git_dirty)$br\[$RS\]"
}
function prompt() {
PS1="\u@\h$(get_git_branch):\w\$ "
export PS1
}
PROMPT_COMMAND=prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment