Skip to content

Instantly share code, notes, and snippets.

@frsela
Created August 1, 2013 10:00
Show Gist options
  • Save frsela/6130059 to your computer and use it in GitHub Desktop.
Save frsela/6130059 to your computer and use it in GitHub Desktop.
GIT Branch in PROMPT (old release)
...
# GIT
# Add git branch name to prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(git::\1)/'
}
parse_svn_branch() {
parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk -F / '{print "(svn::"$1 "/" $2 ")"}'
}
parse_svn_url() {
svn info 2>/dev/null | grep -e '^URL*' | sed -e 's#^URL: *\(.*\)#\1#g '
}
parse_svn_repository_root() {
svn info 2>/dev/null | grep -e '^Repository Root:*' | sed -e 's#^Repository Root: *\(.*\)#\1\/#g '
}
#export PS1="\[\033[00m\]\u@\h\[\033[01;34m\] \w \[\033[31m\]\$(parse_git_branch)\$(parse_svn_branch) \[\033[00m\]$\[\033[00m\] "
# Define some colors first:
red='\e[0;31m'
RED='\e[1;31m'
blue='\e[0;34m'
BLUE='\e[1;34m'
purple='\e[0;35m'
PURPLE='\e[1;35m'
cyan='\e[0;36m'
CYAN='\e[1;36m'
NC='\e[0m' #No color
# Show git branch in bash
function get_git_branch {
git branch | awk '/^\*/ { print $2 }'
}
# red bold cross if changes in branch
function get_git_dirty {
git branch &> /dev/null || return 1
git diff --quiet 2> /dev/null || echo -e " ✘"
}
function get_git_prompt {
git branch &> /dev/null || return 1
echo -e "${cyan}[$(get_git_branch)]${RED}$(get_git_dirty) ${NC}"
}
#export PS1='\w $(get_git_prompt)>: '
export PS1="\!|\[\033[00m\]\u@\h\[\033[01;34m\] \w \[\033[32m\]\$(parse_git_branch)\[\033[31m\]\$(get_git_dirty)\$(parse_svn_branch) \[\033[00m\]$\[\033[00m\] "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment