git/svn info on your bash prompt (oziputils)
History
yesterday i came across this bash script (http://hocuspokus.net/2009/07/add-git-and-svn-branch-to-bash-prompt) then while eating a couple scramble eggs at 4 am i thought that i would be a little bit nicer if i could include the SVN revision number to the script, i took me a couple hours to get it done (sed/awk biatches!) but i did it on the end
How does it work
just enter to any checkout of SVN or a clone of any GIT project, and your prompt will indicate the type of version control and the current branch and also the current revision number (revision will be only on the SVN info)
Git
![]()
SVN
![]()
Download/Source
download the file from the oziputils github project
http://github.com/ozipi/oziputils
or just grab whatever the functions and the PS1 export from the source and put it on your .profile file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 #Colors definition
BLACK="\[\033[0;30m\]"
DARK_GRAY="\[\033[1;30m\]"
LIGHT_GRAY="\[\033[0;37m\]"
BLUE="\[\033[0;34m\]"
LIGHT_BLUE="\[\033[1;34m\]"
GREEN="\[\033[0;32m\]"
LIGHT_GREEN="\[\033[1;32m\]"
CYAN="\[\033[0;36m\]"
LIGHT_CYAN="\[\033[1;36m\]"
RED="\[\033[0;31m\]"
LIGHT_RED="\[\033[1;31m\]"
PURPLE="\[\033[0;35m\]"
LIGHT_PURPLE="\[\033[1;35m\]"
BROWN="\[\033[0;33m\]"
YELLOW="\[\033[1;33m\]"
WHITE="\[\033[1;37m\]"
DEFAULT_COLOR="\[\033[00m\]"
RED_BOLD="\[\033[01;31m\]"
GREEN="\[\033[0;32m\]"
#Get git information
parse_git_branch () {
git name-rev HEAD 2> /dev/null | sed 's#HEAD\ \(.*\)# (git::\1)#'
}
#Get svn information
##Get svn url
parse_svn_url() {
svn info 2>/dev/null | sed -ne 's#^URL: ##p'
}
##Get svn repository root
parse_svn_repository_root() {
svn info 2>/dev/null | sed -ne 's#^Repository Root: ##p'
}
##Get svn revision
parse_svn_current_revision() {
svn info 2>/dev/null | sed -ne 's#^Revision: ##p'
}
##Parse everything and return the svn general info
parse_svn_branch_revision() {
parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk -F / '{print $1 "/" $2 }' | awk '{print " (svn::_@" $1 ")" } ' | sed -e 's#_@#'"$(parse_svn_current_revision)"':#g'
}
export PS1="$DEFAULT_COLOR[$LIGHT_CYAN\u@\h$BLUE $YELLOW\w$LIGHT_PURPLE\$(parse_git_branch)\$(parse_svn_branch_revision)$DEFAULT_COLOR ] "
Thanks to @dazoakley for the script and let’s hope somebody found this useful
Adrian Castillo 11:11 pm on November 20, 2009 Permalink
Thanks ozipi, i had saw this in others coworkers terminals but i never knew how i can do that, you have save me a lot of “git branch” and pay tacos.
Thanks.