commit fc6fcce76b01ef9e569c8ca026ea7b926677f2a4
tree 9c416ff31cca7fee9c99c934758cba09e975e391
parent c7067825cb4dcfa9258a1f09fead7becef45fc51
tree 9c416ff31cca7fee9c99c934758cba09e975e391
parent c7067825cb4dcfa9258a1f09fead7becef45fc51
| b6d269cd » | muness | 2008-06-11 | 1 | _bold=$(tput bold) | |
| 2 | _normal=$(tput sgr0) | ||||
| 3 | |||||
| 5b44a537 » | muness | 2008-06-23 | 4 | __prompt_command() { | |
| 5 | local vcs base_dir sub_dir ref last_command | ||||
| b6d269cd » | muness | 2008-06-11 | 6 | sub_dir() { | |
| 3b708478 » | muness | 2008-06-11 | 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 | 11 | } | |
| 12 | |||||
| e75ec4ee » | relevance | 2009-01-15 | 13 | ||
| 14 | # http://github.com/blog/297-dirty-git-state-in-your-prompt | ||||
| 15 | function parse_git_dirty { | ||||
| 572b6a34 » | relevance | 2009-01-15 | 16 | [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "${_bold}*${_normal}" | |
| e75ec4ee » | relevance | 2009-01-15 | 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 | 22 | git_dir() { | |
| aa251929 » | muness | 2008-08-21 | 23 | base_dir=$(git rev-parse --show-cdup 2>/dev/null) || return 1 | |
| 3b708478 » | muness | 2008-06-11 | 24 | if [ -n "$base_dir" ]; then | |
| 25 | base_dir=`cd $base_dir; pwd` | ||||
| 26 | else | ||||
| 27 | base_dir=$PWD | ||||
| 5b44a537 » | muness | 2008-06-23 | 28 | fi | |
| aa251929 » | muness | 2008-08-21 | 29 | sub_dir=$(git rev-parse --show-prefix) | |
| 3b708478 » | muness | 2008-06-11 | 30 | sub_dir="/${sub_dir%/}" | |
| e75ec4ee » | relevance | 2009-01-15 | 31 | ref=$(parse_git_branch) | |
| 3b708478 » | muness | 2008-06-11 | 32 | vcs="git" | |
| 33 | alias pull="git pull" | ||||
| f7153b94 » | muness | 2008-10-08 | 34 | alias commit="git commit -v -a" | |
| 9503f183 » | muness | 2008-06-12 | 35 | alias push="commit ; git push" | |
| 3b708478 » | muness | 2008-06-11 | 36 | alias revert="git checkout" | |
| b6d269cd » | muness | 2008-06-11 | 37 | } | |
| 38 | |||||
| 39 | svn_dir() { | ||||
| 3b708478 » | muness | 2008-06-11 | 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 | 45 | ref=`svnversion` | |
| 3b708478 » | muness | 2008-06-11 | 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 | 51 | } | |
| 52 | |||||
| c8b9f4e8 » | muness | 2008-06-23 | 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 | 71 | ||
| b6d269cd » | muness | 2008-06-11 | 72 | if [ -n "$vcs" ]; then | |
| 3b708478 » | muness | 2008-06-11 | 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 | 78 | working_on="$base_dir:" | |
| 3b708478 » | muness | 2008-06-11 | 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 | 83 | else | |
| 3b708478 » | muness | 2008-06-11 | 84 | __vcs_prefix='' | |
| 85 | __vcs_base_dir="${PWD/$HOME/~}" | ||||
| 86 | __vcs_ref='' | ||||
| 87 | __vcs_sub_dir='' | ||||
| 5b44a537 » | muness | 2008-06-23 | 88 | working_on="" | |
| b6d269cd » | muness | 2008-06-11 | 89 | fi | |
| 5b44a537 » | muness | 2008-06-23 | 90 | ||
| 91 | last_command=$(history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g") | ||||
| 92 | __tab_title="$working_on[$last_command]" | ||||
| 58bbc3bc » | muness | 2008-06-23 | 93 | __pretty_pwd="${PWD/$HOME/~}" | |
| b6d269cd » | muness | 2008-06-11 | 94 | } | |
| 95 | |||||
| 5b44a537 » | muness | 2008-06-23 | 96 | PROMPT_COMMAND=__prompt_command | |
| 58bbc3bc » | muness | 2008-06-23 | 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 | 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 | 101 | if [ -z "$TM_SUPPORT_PATH"]; then | |
| ccd189d7 » | muness | 2008-06-12 | 102 | case $TERM in | |
| 68c30af1 » | muness | 2008-06-12 | 103 | rxvt|*term|xterm-color) | |
| 5b44a537 » | muness | 2008-06-23 | 104 | trap 'echo -e "\e]1;$working_on>$BASH_COMMAND<\007\c"' DEBUG | |
| ccd189d7 » | muness | 2008-06-12 | 105 | ;; | |
| 106 | esac | ||||
| 68c30af1 » | muness | 2008-06-12 | 107 | fi | |
