Created
January 15, 2013 12:30
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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