summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>2014-05-12 14:19:52 +0100
committerGianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>2014-05-12 14:19:52 +0100
commitf7c4c33841d6d1059837ded5251888b2b692789a (patch)
tree0f82e5df7d8fa92aa13dbb0e5d21f0225d7f87ef
parentfix tag ref cleanup (diff)
parentMerge pull request #35 from maruel/fix_localized (diff)
downloadgit-prompt-f7c4c33841d6d1059837ded5251888b2b692789a.tar.gz
git-prompt-f7c4c33841d6d1059837ded5251888b2b692789a.tar.bz2
git-prompt-f7c4c33841d6d1059837ded5251888b2b692789a.zip
Merge remote-tracking branch 'origin/master' into dakkar
-rwxr-xr-xgit-prompt.sh61
1 files changed, 35 insertions, 26 deletions
diff --git a/git-prompt.sh b/git-prompt.sh
index b81ac02..1eed094 100755
--- a/git-prompt.sh
+++ b/git-prompt.sh
@@ -1,13 +1,25 @@
# don't set prompt if this is not interactive shell
[[ $- != *i* ]] && return
+ # bash version check
+ if [[ -z ${BASH_VERSION} || "${BASH_VERSINFO[0]}" -lt 4 ]]; then
+ echo "git-prompt requires bash-v4 or newer, git-prompt is not enabled."
+ return
+ fi
+
+ # clear vars from previous invocation
+ unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color
+ unset prompt_color jobs_color time_color
+ unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color
+ unset rawhex_len
+
+ # work around for conflict with vte.sh
+ unset VTE_VERSION
+
################################################################### CONFIG
##### read config file if any.
- unset dir_color rc_color jobs_color prompt_color user_id_color root_id_color init_vcs_color clean_vcs_color time_color
- unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color
- unset rawhex_len
conf=git-prompt.conf; [[ -r $conf ]] && . $conf
conf=/etc/git-prompt.conf; [[ -r $conf ]] && . $conf
@@ -170,7 +182,7 @@ cwd_truncate() {
# arg1: max path lenght
# returns abbrivated $PWD in public "cwd" var
- cwd="${PWD/$HOME/~}" # substitute "~"
+ cwd="${PWD/$HOME/~}" # substitute "~"
case $1 in
full)
@@ -178,26 +190,21 @@ cwd_truncate() {
;;
last)
cwd="${PWD##/*/}"
- [[ $PWD == $HOME ]] && cwd="~"
+ [[ "$PWD" == "$HOME" ]] && cwd="~"
return
;;
*)
- # if bash < v3.2 then don't truncate
- if [[ ${BASH_VERSINFO[0]} -eq 3 && ${BASH_VERSINFO[1]} -le 1 || ${BASH_VERSINFO[0]} -lt 3 ]] ; then
- return
- fi
;;
esac
# split path into: head='~/', truncateble middle, last_dir
- local cwd_max_length="$1"
- # expression which bash-3.1 or older can not understand, so we wrap it in eval
- exp31='[[ "$cwd" =~ (~?/)(.*/)([^/]*)$ ]]'
- if eval $exp31 ; then # only valid if path have more then 1 dir
- local path_head="${BASH_REMATCH[1]}"
- local path_middle="${BASH_REMATCH[2]}"
- local path_last_dir="${BASH_REMATCH[3]}"
+ local cwd_max_length=$1
+
+ if [[ "$cwd" =~ '(~?/)(.*/)([^/]*)$' ]] ; then # only valid if path have more than 1 dir
+ local path_head=${BASH_REMATCH[1]}
+ local path_middle=${BASH_REMATCH[2]}
+ local path_last_dir=${BASH_REMATCH[3]}
local cwd_middle_max=$(( $cwd_max_length - ${#path_last_dir} ))
[[ $cwd_middle_max < 0 ]] && cwd_middle_max=0
@@ -210,9 +217,8 @@ cwd_truncate() {
middle_tail="${path_middle:${#path_middle}-${cwd_middle_max}}"
# trunc on dir boundary (trunc 1st, probably tuncated dir)
- exp31='[[ $middle_tail =~ [^/]*/(.*)$ ]]'
- eval $exp31
- middle_tail="${BASH_REMATCH[1]}"
+ [[ $middle_tail =~ '[^/]*/(.*)$' ]]
+ middle_tail=${BASH_REMATCH[1]}
# use truncated only if we cut at least 4 chars
if [[ $(( ${#path_middle} - ${#middle_tail})) -gt 4 ]]; then
@@ -436,16 +442,19 @@ parse_git_status() {
unset branch status modified added clean init added mixed untracked op detached
+ # work around for VTE bug (hang on printf)
+ unset VTE_VERSION
+
# info not in porcelain status
eval " $(
- git status 2>/dev/null |
+ LANG=C git status 2>/dev/null |
sed -n '
- s/^# On branch /branch=/p
+ s/^\(# \)*On branch /branch=/p
s/^nothing to commi.*/clean=clean/p
- s/^# Initial commi.*/init=init/p
- s/^# Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}↑/p
- s/^# Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}↓/p
- s/^# Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}↕/p
+ s/^\(# \)*Initial commi.*/init=init/p
+ s/^\(# \)*Your branch is ahead of \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${WHITE}↑/p
+ s/^\(# \)*Your branch is behind \(.\).\+\1 by [[:digit:]]\+ commit.*/freshness=${YELLOW}↓/p
+ s/^\(# \)*Your branch and \(.\).\+\1 have diverged.*/freshness=${YELLOW}↕/p
'
)"
@@ -461,7 +470,7 @@ parse_git_status() {
# A "with space" <------------- WITH QOUTES
eval " $(
- git status --porcelain 2>/dev/null |
+ LANG=C git status --porcelain 2>/dev/null |
sed -n '
s,^[MARC]. \([^\"][^/]*/\?\).*, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p
s,^[MARC]. \"\([^/]\+/\?\).*\"$, added=added; [[ \" ${added_files[@]} \" =~ \" \1 \" ]] || added_files[${#added_files[@]}]=\"\1\",p