Skip to content

Instantly share code, notes, and snippets.

@giordanocardillo
Created March 16, 2020 09:57
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 giordanocardillo/1ffa74a9698a566eef0164818655ac61 to your computer and use it in GitHub Desktop.
Save giordanocardillo/1ffa74a9698a566eef0164818655ac61 to your computer and use it in GitHub Desktop.
Adding SVN/GIT branch to Git Bash (Windows)
#!/bin/bash
function svn_branch {
svn_info="$(svn info | egrep '^URL: ' 2> /dev/null)"
branch_pattern="^URL: .*/(branches|tags)/([^/]+)"
trunk_pattern="^URL: .*/trunk(/.*)?$"
if [[ ${svn_info} =~ $branch_pattern ]]; then
branch=${BASH_REMATCH[2]}
elif [[ ${svn_info} =~ $trunk_pattern ]]; then
branch='trunk'
fi
}
function git_branch {
git_status="$(git status 2> /dev/null)"
branch_pattern="^[# ]*On branch ([^${IFS}]*)"
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
fi
}
function branch {
branch=""
if [ -d .git ]; then
git_branch
elif [ -d .svn ]; then
svn_branch
fi
if [ ! -z $branch ]; then
echo "($branch)"
fi
}
function set_ps1 {
PS1="\[\033]0;$TITLEPREFIX:$PWD\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\] `branch` \[\033[0m\]\n$ "
}
PROMPT_COMMAND=set_ps1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment