Created
December 4, 2012 04:11
-
-
Save lifeicd/4200515 to your computer and use it in GitHub Desktop.
vcs info on PS1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vcs() { | |
| if [[ -d ".svn" ]] ; then | |
| __svn_branch 2> /dev/null | \ | |
| awk '{ printf "svn:" $1 }' | |
| elif [[ -d ".hg" ]] ; then | |
| hg branch 2> /dev/null | \ | |
| awk '{ printf " hg:on " $1 }' | |
| hg bookmarks 2> /dev/null | \ | |
| awk '/\*/ { printf " hg:at " $2 }' | |
| elif [[ -d .git ]] ; then | |
| git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/git:on\ \1 /' | |
| fi | |
| } | |
| # Outputs the current trunk, branch, or tag | |
| __svn_branch() { | |
| local url= | |
| if [[ -d .svn ]]; then | |
| url=`svn info | awk '/URL:/ {print $2}'` | |
| if [[ $url =~ trunk ]]; then | |
| echo trunk | |
| elif [[ $url =~ /branches/ ]]; then | |
| echo $url | sed -e 's#^.*/\(branches/.*/.*\)$#\1#' | |
| elif [[ $url =~ /tags/ ]]; then | |
| echo $url | sed -e 's#^.*/\(tags/.*\)/.*$#\1#' | |
| fi | |
| fi | |
| } | |
| # Outputs the current revision | |
| __svn_rev() { | |
| local r=$(svn info | awk '/Revision:/ {print $2}') | |
| if [ ! -z $SVN_SHOWDIRTYSTATE ]; then | |
| local svnst flag | |
| svnst=$(svn status | grep '^\s*[?ACDMR?!]') | |
| [ -z "$svnst" ] && flag=* | |
| r=$r$flag | |
| fi | |
| echo $r | |
| } | |
| if [ "$color_prompt" = yes ]; then | |
| PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] $(vcs)\n\$' | |
| else | |
| PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment