Skip to content

Instantly share code, notes, and snippets.

@mb-tmatsuoka
Created August 20, 2012 02:06
Show Gist options
  • Save mb-tmatsuoka/3399290 to your computer and use it in GitHub Desktop.
Save mb-tmatsuoka/3399290 to your computer and use it in GitHub Desktop.
define __svn_ps1 like __git_ps1
__svn_ps1() {
if [[ -d .svn ]]; then
local url=$(svn info | awk '/URL:/ {print $2}')
local repo=$(echo $url | sed 's/^.*\/\(trunk\|branches\|tags\)/\1/')
if $SVN_PS1_SHOWDIRTYSTATE; then
svn st | grep -e '^[MA]' > /dev/null 2>&1
local modified=$(echo $? | sed 's/0/+/' | sed 's/1//')
svn st | grep '^?' > /dev/null 2>&1
local added=$(echo $? | sed 's/0/*/' | sed 's/1//')
fi
if [ "$modified" -o "$added" ]; then
echo " (${repo} ${modified}${added})"
else
echo " (${repo})"
fi
fi
}
@mb-tmatsuoka
Copy link
Author

Example

This is my PS1.

export PS1='[\t]\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)$(__svn_ps1)\[\033[00m\]\$ '

Example.

[11:10:52]user@yourhost:/path/to/project (trunk)$ 

@mb-tmatsuoka
Copy link
Author

If you set env SVN_PS1_SHOWDIRTYSTATE to true it shows a dirtystate;

SVN_PS1_SHOWDIRTYSTATE=true

Examples.

[11:10:52]user@yourhost:/path/to/project (trunk *)$ 
[11:10:52]user@yourhost:/path/to/project (trunk +)$ 
[11:10:52]user@yourhost:/path/to/project (trunk +*)$ 

Dirtystates meanings.

* : untracked file
+ : modified file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment