Skip to content

Instantly share code, notes, and snippets.

@kellishaver
Created September 21, 2014 07:03
Show Gist options
  • Save kellishaver/bb8b3a2473b54860f568 to your computer and use it in GitHub Desktop.
Save kellishaver/bb8b3a2473b54860f568 to your computer and use it in GitHub Desktop.
Customize your command prompt with useful Git info
export TERM=xterm-256color
MAGENTA=$(tput setaf 9)
ORANGE=$(tput setaf 172)
YELLOW=$(tput setaf 190)
PURPLE=$(tput setaf 141)
BOLD=$(tput bold)
RESET=$(tput sgr0)
export MAGENTA
export ORANGE
export YELLOW
export PURPLE
export BOLD
export RESET
function parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && echo "$MAGENTA*$RESET"
}
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
export PS1="\[${BOLD}${ORANGE}\]\u \[$YELLOW\]\w\[$RESET\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on branch: \")\[$PURPLE\]\$(parse_git_branch)\n> \[$RESET\]"
@fuzhengwei
Copy link

hello

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