relevance / etc

bash scripts, aliases, other misc things go here

This URL has Read+Write access

etc / bash / bash_vcs.sh
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 1 _bold=$(tput bold)
2 _normal=$(tput sgr0)
3
5b44a537 » muness 2008-06-23 refactor: build the tab tit... 4 __prompt_command() {
5 local vcs base_dir sub_dir ref last_command
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 6 sub_dir() {
3b708478 » muness 2008-06-11 Make bash goodness 7 local sub_dir
8 sub_dir=$(stat -f "${PWD}")
9 sub_dir=${sub_dir#$1}
10 echo ${sub_dir#/}
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 11 }
12
e75ec4ee » relevance 2009-01-15 dirty git state 13
14 # http://github.com/blog/297-dirty-git-state-in-your-prompt
15 function parse_git_dirty {
572b6a34 » relevance 2009-01-15 bold the dirty status indic... 16 [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "${_bold}*${_normal}"
e75ec4ee » relevance 2009-01-15 dirty git state 17 }
18 function parse_git_branch {
19 git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
20 }
21
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 22 git_dir() {
aa251929 » muness 2008-08-21 git subcommands are no long... 23 base_dir=$(git rev-parse --show-cdup 2>/dev/null) || return 1
3b708478 » muness 2008-06-11 Make bash goodness 24 if [ -n "$base_dir" ]; then
25 base_dir=`cd $base_dir; pwd`
26 else
27 base_dir=$PWD
5b44a537 » muness 2008-06-23 refactor: build the tab tit... 28 fi
aa251929 » muness 2008-08-21 git subcommands are no long... 29 sub_dir=$(git rev-parse --show-prefix)
3b708478 » muness 2008-06-11 Make bash goodness 30 sub_dir="/${sub_dir%/}"
e75ec4ee » relevance 2009-01-15 dirty git state 31 ref=$(parse_git_branch)
3b708478 » muness 2008-06-11 Make bash goodness 32 vcs="git"
33 alias pull="git pull"
f7153b94 » muness 2008-10-08 Make the git commit command... 34 alias commit="git commit -v -a"
9503f183 » muness 2008-06-12 guess what I am working on,... 35 alias push="commit ; git push"
3b708478 » muness 2008-06-11 Make bash goodness 36 alias revert="git checkout"
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 37 }
38
39 svn_dir() {
3b708478 » muness 2008-06-11 Make bash goodness 40 [ -d ".svn" ] || return 1
41 base_dir="."
42 while [ -d "$base_dir/../.svn" ]; do base_dir="$base_dir/.."; done
43 base_dir=`cd $base_dir; pwd`
44 sub_dir="/$(sub_dir "${base_dir}")"
c55e37b3 » muness 2009-04-23 simplify extracting version 45 ref=`svnversion`
3b708478 » muness 2008-06-11 Make bash goodness 46 vcs="svn"
47 alias pull="svn up"
48 alias commit="svn commit"
49 alias push="svn ci"
50 alias revert="svn revert"
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 51 }
52
c8b9f4e8 » muness 2008-06-23 nikolaj patch to add bzr su... 53 bzr_dir() {
54 base_dir=$(bzr root 2>/dev/null) || return 1
55 if [ -n "$base_dir" ]; then
56 base_dir=`cd $base_dir; pwd`
57 else
58 base_dir=$PWD
59 fi
60 sub_dir="/$(sub_dir "${base_dir}")"
61 ref=$(bzr revno 2>/dev/null)
62 vcs="bzr"
63 alias pull="bzr pull"
64 alias commit="bzr commit"
65 alias push="bzr push"
66 alias revert="bzr revert"
67 }
68
69
70 git_dir || svn_dir || bzr_dir
3b708478 » muness 2008-06-11 Make bash goodness 71
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 72 if [ -n "$vcs" ]; then
3b708478 » muness 2008-06-11 Make bash goodness 73 alias st="$vcs status"
74 alias d="$vcs diff"
75 alias up="pull"
76 alias cdb="cd $base_dir"
77 base_dir="$(basename "${base_dir}")"
5b44a537 » muness 2008-06-23 refactor: build the tab tit... 78 working_on="$base_dir:"
3b708478 » muness 2008-06-11 Make bash goodness 79 __vcs_prefix="($vcs)"
80 __vcs_ref="[$ref]"
81 __vcs_sub_dir="${sub_dir}"
82 __vcs_base_dir="${base_dir/$HOME/~}"
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 83 else
3b708478 » muness 2008-06-11 Make bash goodness 84 __vcs_prefix=''
85 __vcs_base_dir="${PWD/$HOME/~}"
86 __vcs_ref=''
87 __vcs_sub_dir=''
5b44a537 » muness 2008-06-23 refactor: build the tab tit... 88 working_on=""
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 89 fi
5b44a537 » muness 2008-06-23 refactor: build the tab tit... 90
91 last_command=$(history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g")
92 __tab_title="$working_on[$last_command]"
58bbc3bc » muness 2008-06-23 refactor for readability 93 __pretty_pwd="${PWD/$HOME/~}"
b6d269cd » muness 2008-06-11 bash vcs love (svn and git) 94 }
95
5b44a537 » muness 2008-06-23 refactor: build the tab tit... 96 PROMPT_COMMAND=__prompt_command
58bbc3bc » muness 2008-06-23 refactor for readability 97 PS1='\[\e]2;\h::$__pretty_pwd\a\e]1;$__tab_title\a\]\u:$__vcs_prefix\[${_bold}\]${__vcs_base_dir}\[${_normal}\]${__vcs_ref}\[${_bold}\]${__vcs_sub_dir}\[${_normal}\]\$ '
3b708478 » muness 2008-06-11 Make bash goodness 98
99 # Show the currently running command in the terminal title:
100 # http://www.davidpashley.com/articles/xterm-titles-with-bash.html
68c30af1 » muness 2008-06-12 textmate is a pain 101 if [ -z "$TM_SUPPORT_PATH"]; then
ccd189d7 » muness 2008-06-12 don't be noisy in non-termi... 102 case $TERM in
68c30af1 » muness 2008-06-12 textmate is a pain 103 rxvt|*term|xterm-color)
5b44a537 » muness 2008-06-23 refactor: build the tab tit... 104 trap 'echo -e "\e]1;$working_on>$BASH_COMMAND<\007\c"' DEBUG
ccd189d7 » muness 2008-06-12 don't be noisy in non-termi... 105 ;;
106 esac
68c30af1 » muness 2008-06-12 textmate is a pain 107 fi