zachinglis / dotfiles

My dotfiles

This URL has Read+Write access

zachinglis (author)
Mon Nov 03 04:54:11 -0800 2008
commit  59095d904c3fb70f253e7342f58667049bb69b46
tree    b46a3a61a6c40309b451956609fbf05d61e70838
parent  38d718a0fa35204e01b9523da582510de274a918
dotfiles / .bash_vcs
100644 71 lines (63 sloc) 1.764 kb
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
_bold=$(tput bold)
_normal=$(tput sgr0)
 
 
__vcs_dir() {
local vcs base_dir sub_dir ref
sub_dir() {
local sub_dir
sub_dir=$(stat -f "${PWD}")
sub_dir=${sub_dir#$1}
echo ${sub_dir#/}
}
 
git_dir() {
base_dir=$(git-rev-parse --show-cdup 2>/dev/null) || return 1
if [ -n "$base_dir" ]; then
base_dir=`cd $base_dir; pwd`
else
          base_dir=$PWD
         fi
         sub_dir=$(git-rev-parse --show-prefix)
sub_dir="/${sub_dir%/}"
ref=$(git-symbolic-ref -q HEAD || git-name-rev --name-only HEAD 2>/dev/null)
ref=${ref#refs/heads/}
vcs="git"
base_dir="$(basename "${base_dir}")"
alias pull="git pull"
alias add="git add ."
alias commit="git commit"
alias push="commit && git push"
alias revert="git checkout"
alias status="git status"
}
 
svn_dir() {
[ -d ".svn" ] || return 1
base_dir="."
while [ -d "$base_dir/../.svn" ]; do base_dir="$base_dir/.."; done
base_dir=`cd $base_dir; pwd`
sub_dir="/$(sub_dir "${base_dir}")"
ref=$(svn info "$base_dir" | awk '/^URL/ { sub(".*/","",$0); r=$0 } /^Revision/ { sub("[^0-9]*","",$0); print r":"$0 }')
vcs="svn"
base_dir="$(basename "${base_dir}")"
alias pull="svn up"
alias commit="svn commit"
alias push="svn ci"
alias revert="svn revert"
alias status="svn status"
}
 
git_dir || svn_dir
 
if [ -n "$vcs" ]; then
__vcs_prefix="($vcs)"
__vcs_base_dir="${base_dir/$HOME/~}"
__vcs_ref="[$ref]"
__vcs_sub_dir="${sub_dir}"
  alias st="$vcs status"
alias d="$vcs diff"
         alias up="pull"
else
__vcs_prefix=''
__vcs_base_dir="${PWD/$HOME/~}"
__vcs_ref=''
__vcs_sub_dir=''
fi
}
 
PROMPT_COMMAND=__vcs_dir
PS1='\u:$__vcs_prefix\[${_bold}\]${__vcs_base_dir}\[${_normal}\]${__vcs_ref}\[${_bold}\]${__vcs_sub_dir}\[${_normal}\]\$ '