Merge remote-tracking branch 'original/master'

* original/master:
  Fixed Symbols for ahead and behind
  Colorized git-prompt-help with configured colors and symbols
  Added sourcing of git_prompt_help.sh to gitprompt.sh
  Associative arrays does not work on Bash 3 (OS X for instance). Change to ordinary variables to be more compatible.
master
Alan Stebbens 12 years ago
commit 06f7578ccd
  1. 38
      git-prompt-help.sh
  2. 3
      gitprompt.sh
  3. 13
      gitstatus.sh

@ -3,7 +3,7 @@
# being displayed. # being displayed.
git_prompt_help() { git_prompt_help() {
cat <<EOF 1>&2 cat <<EOF | sed 's/\\\[\\033//g' | sed 's/\\\]//g'
The git prompt format is [<BRANCH><TRACKING>|<LOCALSTATUS>] The git prompt format is [<BRANCH><TRACKING>|<LOCALSTATUS>]
BRANCH is a branch name, such as "master" or "stage", a tag name, or commit BRANCH is a branch name, such as "master" or "stage", a tag name, or commit
@ -12,44 +12,46 @@ hash prefixed with ':'.
TRACKING indicates how the local branch differs from the TRACKING indicates how the local branch differs from the
remote branch. It can be empty, or one of: remote branch. It can be empty, or one of:
↑N - ahead of remote by N commits ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}·N${ResetColor} - ahead of remote by N commits
↓N - behind remote by N commits ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}·N${ResetColor} - behind remote by N commits
↓M↑N - branches diverged, other by M commits, yours by N commits ${GIT_PROMPT_BRANCH}${ResetColor}${GIT_PROMPT_REMOTE}·M↑·N${ResetColor} - branches diverged, other by M commits, yours by N commits
LOCALSTATUS is one of the following: LOCALSTATUS is one of the following:
- repository clean ${GIT_PROMPT_CLEAN}${ResetColor} - repository clean
●N - N staged files ${GIT_PROMPT_STAGED}N${ResetColor} - N staged files
✖N - N unmerged files ${GIT_PROMPT_CONFLICTS}N${ResetColor} - N conflicted files
✚N - N changed but *unstaged* files ${GIT_PROMPT_CHANGED}N${ResetColor} - N changed but *unstaged* files
…N - N untracked files ${GIT_PROMPT_UNTRACKED}N${ResetColor} - N untracked files
⚑N - N stash entries ${GIT_PROMPT_STASHED}N${ResetColor} - N stash entries
See "git_prompt_examples" for examples. See "git_prompt_examples" for examples.
EOF EOF
} }
help_git_prompt() { git_prompt_help ; } help_git_prompt() { git_prompt_help ; }
git_prompt_examples() { git_prompt_examples() {
cat <<EOF 1>&2 cat <<EOF | sed 's/\\\[\\033//g' | sed 's/\\\]//g'
These are examples of the git prompt: These are examples of the git prompt:
(master↑3|✚1) - on branch "master", ahead of remote by 3 commits, 1 [${GIT_PROMPT_BRANCH}master${ResetColor}${GIT_PROMPT_REMOTE}↑·3${ResetColor}|${GIT_PROMPT_CHANGED}1${ResetColor}] - on branch "master", ahead of remote by 3 commits, 1
file changed but not staged file changed but not staged
(status|●2) - on branch "status", 2 files staged [${GIT_PROMPT_BRANCH}status${ResetColor}|${GIT_PROMPT_STAGED}2${ResetColor}] - on branch "status", 2 files staged
(master|✚7…) - on branch "master", 7 files changed, some files untracked [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_CHANGED}7${GIT_PROMPT_UNTRACKED}${ResetColor}] - on branch "master", 7 files changed, some files untracked
(master|✖2✚3) - on branch "master", 2 conflicts, 3 files changed [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_CONFLICTS}2${GIT_PROMPT_CHANGED}3${ResetColor}] - on branch "master", 2 conflicts, 3 files changed
(master|⚑2) - on branch "master", 2 stash entries [${GIT_PROMPT_BRANCH}master${ResetColor}|${GIT_PROMPT_STASHED}2${ResetColor}] - on branch "master", 2 stash entries
(experimental↓2↑3|) - on branch "experimental"; your branch has diverged [${GIT_PROMPT_BRANCH}experimental${ResetColor}${GIT_PROMPT_REMOTE}↓·2↑·3${ResetColor}|${GIT_PROMPT_CLEAN}${ResetColor}]
- on branch "experimental"; your branch has diverged
by 3 commits, remote by 2 commits; the repository is by 3 commits, remote by 2 commits; the repository is
otherwise clean otherwise clean
(:70c2952|) - not on any branch; parent commit has hash "70c2952"; the [${GIT_PROMPT_BRANCH}:70c2952${ResetColor}|${GIT_PROMPT_CLEAN}${ResetColor}] - not on any branch; parent commit has hash "70c2952"; the
repository is otherwise clean repository is otherwise clean
EOF EOF
} }

@ -253,3 +253,6 @@ else
PROMPT_COMMAND=${PROMPT_COMMAND%\;}; # remove trailing semi-colon PROMPT_COMMAND=${PROMPT_COMMAND%\;}; # remove trailing semi-colon
PROMPT_COMMAND="$PROMPT_COMMAND;setGitPrompt" PROMPT_COMMAND="$PROMPT_COMMAND;setGitPrompt"
fi fi
git_prompt_dir
source $__GIT_PROMPT_DIR/git-prompt-help.sh

@ -6,10 +6,9 @@
# Alan K. Stebbens <aks@stebbens.org> [http://github.com/aks] # Alan K. Stebbens <aks@stebbens.org> [http://github.com/aks]
# change those symbols to whatever you prefer # change those symbols to whatever you prefer
declare -a symbols symbols_ahead='↑·'
symbols['ahead']='↑·' symbols_behind='↓·'
symbols['behind']='↓·' symbols_prehash=':'
symbols['prehash']=':'
gitsym=`git symbolic-ref HEAD` gitsym=`git symbolic-ref HEAD`
@ -52,7 +51,7 @@ if [[ -z "$branch" ]]; then
if [[ -n "$tag" ]]; then if [[ -n "$tag" ]]; then
branch="$tag" branch="$tag"
else else
branch="${symbols['prehash']}`git rev-parse --short HEAD`" branch="${symbols_prehash}`git rev-parse --short HEAD`"
fi fi
else else
remote_name=`git config branch.${branch}.remote` remote_name=`git config branch.${branch}.remote`
@ -73,10 +72,10 @@ else
num_ahead=`count_lines "^>"` num_ahead=`count_lines "^>"`
num_behind=$(( num_revs - num_ahead )) num_behind=$(( num_revs - num_ahead ))
if (( num_behind > 0 )) ; then if (( num_behind > 0 )) ; then
remote="${remote}${symbols['behind']}${num_behind}" remote="${remote}${symbols_behind}${num_behind}"
fi fi
if (( num_ahead > 0 )) ; then if (( num_ahead > 0 )) ; then
remote="${remote}${symbols['ahead']}${num_ahead}" remote="${remote}${symbols_ahead}${num_ahead}"
fi fi
fi fi
if [[ -z "$remote" ]] ; then if [[ -z "$remote" ]] ; then

Loading…
Cancel
Save