Skip to content

Instantly share code, notes, and snippets.

@jou
Created November 26, 2008 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jou/29463 to your computer and use it in GitHub Desktop.
Save jou/29463 to your computer and use it in GitHub Desktop.
# set variables for git prompt
set_current_git_branch(){
CURRENT_GIT_BRANCH=`git branch 2>/dev/null | grep '* ' | sed s/'* '//` ;
GIT_BRANCH_TEXT=''
GIT_BRANCH_COLOR=''
if [[ $CURRENT_GIT_BRANCH ]]; then
GIT_BRANCH_TEXT="(git:$CURRENT_GIT_BRANCH) "
GIT_BRANCH_COLOR="\[\033[01;31m\]"
fi
}
# generate and set prompt
set_prompt(){
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in xterm-color|screen)
export PS1="${GIT_BRANCH_COLOR}${GIT_BRANCH_TEXT}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\
$ "
;;
*)
export PS1="${GIT_BRANCH_TEXT}\u@\h:\w\$ "
;;
esac
}
PROMPT_COMMAND="$PROMPT_COMMAND set_current_git_branch; set_prompt; "
# If this is an xterm set the title to (git:branch) user@host:dir
case "$TERM" in
xterm*|rxvt*)
PROMPT_COMMAND=$PROMPT_COMMAND' echo -ne "\033]0;${GIT_BRANCH_TEXT}${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"; '
;;
*)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment