1
0
Fork 0

update git-prompt.plugin.zsh to coding standards: shiftwidth=2, and rename some variable names to remove leading underscores

pull/2/head
Ashley Dev 14 years ago
parent b5179f6c49
commit 51e7a6ebe1

@ -16,46 +16,46 @@
# (See the ashleydev theme for more complex usage.) # (See the ashleydev theme for more complex usage.)
# ---------------------- SAMPLE THEME FILE ------------------------ # ---------------------- SAMPLE THEME FILE ------------------------
# #
# # this is a simple example PROMPT with only git # # this is a simple example PROMPT with only git
# # info from this plugin in it: # # info from this plugin in it:
# PROMPT='$__GIT_PROMPT_INFO# ' # PROMPT='$_GIT_PROMPT_INFO# '
# #
# #GIT_PROMPT_SHORTCIRCUIT='off' # #GIT_PROMPT_SHORTCIRCUIT='off'
# #
# # GIT_PROMPT_INFO_FUNC must be set to the # # GIT_PROMPT_INFO_FUNC must be set to the
# # function that defines your prompt info # # function that defines your prompt info
# # in order to turn this plugin on. # # in order to turn this plugin on.
# GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO' # GIT_PROMPT_INFO_FUNC='update__GIT_PROMPT_INFO'
# #
# local __GIT_PROMPT_INFO='' # local _GIT_PROMPT_INFO=''
# update__GIT_PROMPT_INFO () # update__GIT_PROMPT_INFO ()
# { # {
# _git_prompt__branch # git_prompt__branch
# local b=$GIT_PROMPT_BRANCH # local b=$GIT_PROMPT_BRANCH
# #
# _git_prompt__dirty_state # git_prompt__dirty_state
# local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY # local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY
# local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY # local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY
# #
# # Reset color # # Reset color
# local R="%{$terminfo[sgr0]%}" # local R="%{$terminfo[sgr0]%}"
# #
# if [ "$i" = "yes" ]; then # if [[ "$i" = "yes" ]]; then
# i="%{$bold_color$fg[red]%}+$R" # i="%{$bold_color$fg[red]%}+$R"
# else # else
# i="" # i=""
# fi # fi
# #
# if [ -n "$b" ]; then # if [[ -n "$b" ]]; then
# if [ "$w" = 'yes' ]; then # if [[ "$w" = 'yes' ]]; then
# b="%{$fg_no_bold[red]%}$b$R" # b="%{$fg_no_bold[red]%}$b$R"
# elif [ "$w" = 'no' ]; then # elif [[ "$w" = 'no' ]]; then
# b="%{$fg_no_bold[green]%}$b$R" # b="%{$fg_no_bold[green]%}$b$R"
# fi # fi
# fi # fi
# #
# __GIT_PROMPT_INFO="$R($b$i)$R" # __GIT_PROMPT_INFO="$R($b$i)$R"
# } # }
# ----------------------------------------------------------------- # -----------------------------------------------------------------
# #
# #
@ -66,22 +66,22 @@
# https://github.com/git/git/blob/master/contrib/completion/git-completion.bash # https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
# #
# _git_prompt__git_dir accepts 0 or 1 arguments (i.e., location) # git_prompt__git_dir accepts 0 or 1 arguments (i.e., location)
# echos the location of .git repo. # echos the location of .git repo.
# Useful for quickly figuring out if cwd is under a git repo. # Useful for quickly figuring out if cwd is under a git repo.
_git_prompt__git_dir () git_prompt__git_dir ()
{ {
if [ -z "${1-}" ]; then if [[ -z "${1-}" ]]; then
if [ -d .git ]; then if [[ -d .git ]]; then
echo .git echo .git
else
git rev-parse --git-dir 2>/dev/null
fi
elif [ -d "$1/.git" ]; then
echo "$1/.git"
else else
echo "$1" git rev-parse --git-dir 2>/dev/null
fi fi
elif [[ -d "$1/.git" ]]; then
echo "$1/.git"
else
echo "$1"
fi
} }
# sets GIT_PROMPT_UPSTREAM_STATE # sets GIT_PROMPT_UPSTREAM_STATE
@ -100,243 +100,243 @@ _git_prompt__git_dir ()
# versions of git-rev-list # versions of git-rev-list
# git always compare HEAD to @{upstream} # git always compare HEAD to @{upstream}
# svn always compare HEAD to your SVN upstream # svn always compare HEAD to your SVN upstream
# By default, _git_prompt__upstream will compare HEAD to your SVN upstream # By default, git_prompt__upstream will compare HEAD to your SVN upstream
# if it can find one, or @{upstream} otherwise. Once you have # if it can find one, or @{upstream} otherwise. Once you have
# set GIT_PROMPT_SHOWUPSTREAM, you can override it on a # set GIT_PROMPT_SHOWUPSTREAM, you can override it on a
# per-repository basis by setting the prompt.showUpstream config # per-repository basis by setting the prompt.showUpstream config
# variable (i.e. `git config prompt.showUpstream 'verbose legacy'`). # variable (i.e. `git config prompt.showUpstream 'verbose legacy'`).
# #
# _git_prompt__upstream accepts 0 or 1 arguments. If an argument is given, it # git_prompt__upstream accepts 0 or 1 arguments. If an argument is given, it
# must be a string of the form specified above for GIT_PROMPT_SHOWUPSTREAM. # must be a string of the form specified above for GIT_PROMPT_SHOWUPSTREAM.
# Setting this argument will override any value set for GIT_PROMPT_SHOWUPSTREAM # Setting this argument will override any value set for GIT_PROMPT_SHOWUPSTREAM
# or in the .git/config. # or in the .git/config.
_git_prompt__upstream () git_prompt__upstream ()
{ {
GIT_PROMPT_UPSTREAM_STATE='' GIT_PROMPT_UPSTREAM_STATE=''
if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
return return
fi fi
local key value local key value
local svn_remote svn_url_pattern count n local svn_remote svn_url_pattern count n
local upstream=git legacy="" verbose="" local upstream=git legacy="" verbose=""
local p local p
# get some config options from git-config # get some config options from git-config
while read key value; do while read key value; do
case "$key" in case "$key" in
prompt.showupstream*) prompt.showupstream*)
GIT_PROMPT_SHOWUPSTREAM="$value" GIT_PROMPT_SHOWUPSTREAM="$value"
;; ;;
svn-remote.*.url) svn-remote.*.url)
svn_remote=( "${svn_remote[@]}" $value ) svn_remote=( "${svn_remote[@]}" $value )
svn_url_pattern="$svn_url_pattern\\|$value" svn_url_pattern="$svn_url_pattern\\|$value"
upstream=svn+git # default upstream is SVN if available, else git upstream=svn+git # default upstream is SVN if available, else git
;; ;;
esac
done < <(git config --get-regexp '^(svn-remote\..*\.url|prompt\.showupstream)' 2>/dev/null)
if [ -n "${1-}" ]; then
GIT_PROMPT_SHOWUPSTREAM=$1
fi
# parse configuration values
for option in ${GIT_PROMPT_SHOWUPSTREAM}; do
case "$option" in
off) return ;;
git|svn) upstream="$option" ;;
verbose) verbose=1 ;;
legacy) legacy=1 ;;
esac
done
# Find our upstream
case "$upstream" in
git) upstream="@{upstream}" ;;
svn*)
# get the upstream from the "git-svn-id: ..." in a commit message
# (git-svn uses essentially the same procedure internally)
local svn_upstream=$(git log --first-parent -1 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null | awk '/commit / { print $2 }')
if [[ 0 -ne ${#svn_upstream[@]} ]]; then
if [[ -z "$svn_upstream" ]]; then
# default branch name for checkouts with no layout:
upstream='git-svn'
else
upstream=${svn_upstream#/}
fi
elif [[ "svn+git" = "$upstream" ]]; then
upstream="@{upstream}"
fi
;;
esac esac
done < <(git config --get-regexp '^(svn-remote\..*\.url|prompt\.showupstream)' 2>/dev/null)
# Find how many commits we are ahead/behind our upstream
# produce equivalent output to --count for older versions of git if [[ -n "${1-}" ]]; then
local ahead behind GIT_PROMPT_SHOWUPSTREAM=$1
if git rev-list --left-right "$upstream"...HEAD >/dev/null 2>&1; then fi
behind="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^<' | wc -l | tr -d ' ' 2>/dev/null)"
ahead="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^[^<]' | wc -l | tr -d ' ' 2>/dev/null)" # parse configuration values
count="$behind $ahead" for option in ${GIT_PROMPT_SHOWUPSTREAM}; do
fi case "$option" in
off) return ;;
# calculate the result git|svn) upstream="$option" ;;
if [[ -z "$verbose" ]]; then verbose) verbose=1 ;;
case "$count" in legacy) legacy=1 ;;
"") # no upstream esac
p="" ;; done
"0 0") # equal to upstream
p="=" ;; # Find our upstream
"0 "*) # ahead of upstream case "$upstream" in
p=">" ;; git) upstream="@{upstream}" ;;
*" 0") # behind upstream svn*)
p="<" ;; # get the upstream from the "git-svn-id: ..." in a commit message
*) # diverged from upstream # (git-svn uses essentially the same procedure internally)
p="<>" ;; local svn_upstream=$(git log --first-parent -1 --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null | awk '/commit / { print $2 }')
esac if [[ 0 -ne ${#svn_upstream[@]} ]]; then
else if [[ -z "$svn_upstream" ]]; then
case "$count" in # default branch name for checkouts with no layout:
"") # no upstream upstream='git-svn'
p="" ;; else
"0 0") # equal to upstream upstream=${svn_upstream#/}
p="=" ;; fi
"0 "*) # ahead of upstream elif [[ "svn+git" = "$upstream" ]]; then
p="+${count#0 }" ;; upstream="@{upstream}"
*" 0") # behind upstream
p="-${count% 0}" ;;
*) # diverged from upstream
p="-${count% *}+${count#* }" ;;
esac
fi fi
;;
esac
# Find how many commits we are ahead/behind our upstream
# produce equivalent output to --count for older versions of git
local ahead behind
if git rev-list --left-right "$upstream"...HEAD >/dev/null 2>&1; then
behind="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^<' | wc -l | tr -d ' ' 2>/dev/null)"
ahead="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null | grep '^[^<]' | wc -l | tr -d ' ' 2>/dev/null)"
count="$behind $ahead"
fi
# calculate the result
if [[ -z "$verbose" ]]; then
case "$count" in
"") # no upstream
p="" ;;
"0 0") # equal to upstream
p="=" ;;
"0 "*) # ahead of upstream
p=">" ;;
*" 0") # behind upstream
p="<" ;;
*) # diverged from upstream
p="<>" ;;
esac
else
case "$count" in
"") # no upstream
p="" ;;
"0 0") # equal to upstream
p="=" ;;
"0 "*) # ahead of upstream
p="+${count#0 }" ;;
*" 0") # behind upstream
p="-${count% 0}" ;;
*) # diverged from upstream
p="-${count% *}+${count#* }" ;;
esac
fi
GIT_PROMPT_UPSTREAM_STATE=$p GIT_PROMPT_UPSTREAM_STATE=$p
} }
# sets GIT_PROMPT_REBASE_INFO # sets GIT_PROMPT_REBASE_INFO
# with info about a rebase/merge/etc if it's in progress. # with info about a rebase/merge/etc if it's in progress.
_git_prompt__rebase_info () git_prompt__rebase_info ()
{ {
GIT_PROMPT_REBASE_INFO='' GIT_PROMPT_REBASE_INFO=''
if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
return return
fi fi
if [ "$GIT_PROMPT_SHOWREBASEINFO" = 'off' ]; then if [[ "$GIT_PROMPT_SHOWREBASEINFO" = 'off' ]]; then
return return
fi fi
if [ "$(git config --bool prompt.showRebaseInfo)" = "false" ]; then if [[ "$(git config --bool prompt.showRebaseInfo)" = "false" ]]; then
return return
fi fi
local r="" local r=""
local g="$(_git_prompt__git_dir)" local g="$(git_prompt__git_dir)"
if [ -n "$g" ]; then if [[ -n "$g" ]]; then
if [ -f "$g/rebase-merge/interactive" ]; then if [[ -f "$g/rebase-merge/interactive" ]]; then
r="|REBASE-i" r="|REBASE-i"
elif [ -d "$g/rebase-merge" ]; then elif [[ -d "$g/rebase-merge" ]]; then
r="|REBASE-m" r="|REBASE-m"
else
if [[ -d "$g/rebase-apply" ]]; then
if [[ -f "$g/rebase-apply/rebasing" ]]; then
r="|REBASE"
elif [[ -f "$g/rebase-apply/applying" ]]; then
r="|AM"
else else
if [ -d "$g/rebase-apply" ]; then r="|AM/REBASE"
if [ -f "$g/rebase-apply/rebasing" ]; then
r="|REBASE"
elif [ -f "$g/rebase-apply/applying" ]; then
r="|AM"
else
r="|AM/REBASE"
fi
elif [ -f "$g/MERGE_HEAD" ]; then
r="|MERGING"
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
r="|CHERRY-PICKING"
elif [ -f "$g/BISECT_LOG" ]; then
r="|BISECTING"
fi
fi fi
elif [[ -f "$g/MERGE_HEAD" ]]; then
r="|MERGING"
elif [[ -f "$g/CHERRY_PICK_HEAD" ]]; then
r="|CHERRY-PICKING"
elif [[ -f "$g/BISECT_LOG" ]]; then
r="|BISECTING"
fi
fi fi
fi
GIT_PROMPT_REBASE_INFO=$r GIT_PROMPT_REBASE_INFO=$r
} }
# sets GIT_PROMPT_BRANCH # sets GIT_PROMPT_BRANCH
# with the branch name # with the branch name
_git_prompt__branch () git_prompt__branch ()
{ {
GIT_PROMPT_BRANCH='' GIT_PROMPT_BRANCH=''
if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
return return
fi fi
if [ "$GIT_PROMPT_SHOWBRANCH" = 'off' ]; then if [[ "$GIT_PROMPT_SHOWBRANCH" = 'off' ]]; then
return return
fi fi
if [ "$(git config --bool prompt.showBranch)" = "false" ]; then if [[ "$(git config --bool prompt.showBranch)" = "false" ]]; then
return return
fi
local b=""
local g="$(git_prompt__git_dir)"
if [[ -n "$g" ]]; then
if [[ -f "$g/rebase-merge/interactive" ]]; then
b="$(cat "$g/rebase-merge/head-name")"
elif [[ -d "$g/rebase-merge" ]]; then
b="$(cat "$g/rebase-merge/head-name")"
else
b="$(git symbolic-ref HEAD 2>/dev/null)" || {
b="$(
case "${GIT_PROMPT_DESCRIBE_STYLE-}" in
(contains)
git describe --contains HEAD ;;
(branch)
git describe --contains --all HEAD ;;
(describe)
git describe HEAD ;;
(* | default)
git describe --tags --exact-match HEAD ;;
esac 2>/dev/null)" ||
b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)" ||
b="$b"
}
fi fi
b=${b##refs/heads/}
local b="" if [[ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]]; then
local g="$(_git_prompt__git_dir)" if [[ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]]; then
if [ -n "$g" ]; then b="BARE:$b"
if [ -f "$g/rebase-merge/interactive" ]; then else
b="$(cat "$g/rebase-merge/head-name")" b="GIT_DIR!"
elif [ -d "$g/rebase-merge" ]; then fi
b="$(cat "$g/rebase-merge/head-name")"
else
b="$(git symbolic-ref HEAD 2>/dev/null)" || {
b="$(
case "${GIT_PROMPT_DESCRIBE_STYLE-}" in
(contains)
git describe --contains HEAD ;;
(branch)
git describe --contains --all HEAD ;;
(describe)
git describe HEAD ;;
(* | default)
git describe --tags --exact-match HEAD ;;
esac 2>/dev/null)" ||
b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)" ||
b="$b"
}
fi
b=${b##refs/heads/}
if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
b="BARE:$b"
else
b="GIT_DIR!"
fi
fi
fi fi
fi
GIT_PROMPT_BRANCH=$b GIT_PROMPT_BRANCH=$b
} }
# sets GIT_PROMPT_STASH_STATE_DIRTY # sets GIT_PROMPT_STASH_STATE_DIRTY
# if the git stash state is dirty # if the git stash state is dirty
_git_prompt__stash () git_prompt__stash ()
{ {
GIT_PROMPT_STASH_STATE_DIRTY='' GIT_PROMPT_STASH_STATE_DIRTY=''
if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
return return
fi fi
if [ "$GIT_PROMPT_SHOWSTASHSTATE" = 'off' ]; then if [[ "$GIT_PROMPT_SHOWSTASHSTATE" = 'off' ]]; then
return return
fi fi
if [ "$(git config --bool prompt.showStashState)" = "false" ]; then if [[ "$(git config --bool prompt.showStashState)" = "false" ]]; then
return return
fi fi
if git rev-parse --verify refs/stash >/dev/null 2>&1; then if git rev-parse --verify refs/stash >/dev/null 2>&1; then
GIT_PROMPT_STASH_STATE_DIRTY='yes' GIT_PROMPT_STASH_STATE_DIRTY='yes'
else else
GIT_PROMPT_STASH_STATE_DIRTY='no' GIT_PROMPT_STASH_STATE_DIRTY='no'
fi fi
} }
@ -352,146 +352,146 @@ _git_prompt__stash ()
# #
# NOTE: To make the short-circuit logic work, the GIT_PROMPT_INFO_FUNC function # NOTE: To make the short-circuit logic work, the GIT_PROMPT_INFO_FUNC function
# must set a global variable (with your git prompt format), rather than echo it. # must set a global variable (with your git prompt format), rather than echo it.
# Correct: # Correct:
# #
# PROMPT='$__GIT_PROMPT_INFO > ' # PROMPT='$__GIT_PROMPT_INFO > '
# #
# # this function sets $__GIT_PROMPT_INFO # # this function sets $__GIT_PROMPT_INFO
# function update_prompt_func () # function update_prompt_func ()
# { # {
# #... # #...
# __GIT_PROMPT_INFO="$info" # __GIT_PROMPT_INFO="$info"
# } # }
# GIT_PROMPT_INFO_FUNC=update_prompt_func # GIT_PROMPT_INFO_FUNC=update_prompt_func
# #
# Incorrect: # Incorrect:
# #
# PROMPT='$(update_prompt_func) > ' # PROMPT='$(update_prompt_func) > '
# #
# function update_prompt_func () # function update_prompt_func ()
# { # {
# #... # #...
# echo "$info" # echo "$info"
# } # }
# GIT_PROMPT_INFO_FUNC=update_prompt_func # GIT_PROMPT_INFO_FUNC=update_prompt_func
# #
local _big_repo='init' local _big_repo='init'
__git_prompt_shortcircuit () __git_prompt_shortcircuit ()
{ {
if [[ "$_big_repo" == 'yes' ]]; then if [[ "$_big_repo" == 'yes' ]]; then
_big_repo='' _big_repo=''
if [ "$GIT_PROMPT_SHORTCIRCUIT" != 'off' ]; then if [[ "$GIT_PROMPT_SHORTCIRCUIT" != 'off' ]]; then
echo "$fg[red]" > /dev/stderr echo "$fg[red]" > /dev/stderr
echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: Looks like you hit ctrl-c." > /dev/stderr echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: Looks like you hit ctrl-c." > /dev/stderr
echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: So for this repo I'm setting:" > /dev/stderr echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: So for this repo I'm setting:" > /dev/stderr
echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: git config prompt.showDirtyState false" > /dev/stderr echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: git config prompt.showDirtyState false" > /dev/stderr
echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: On big git repos it takes a long time to get info for your prompt." > /dev/stderr echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: On big git repos it takes a long time to get info for your prompt." > /dev/stderr
echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: To revert it, run:" > /dev/stderr echo "${bold_color}SHELL PROMPT$fg_no_bold[red]: To revert it, run:" > /dev/stderr
echo "${bold_color}SHELL PROMPT$fg_no_bold[red]:$reset_color git config prompt.showDirtyState true" > /dev/stderr echo "${bold_color}SHELL PROMPT$fg_no_bold[red]:$reset_color git config prompt.showDirtyState true" > /dev/stderr
echo '' > /dev/stderr echo '' > /dev/stderr
git config prompt.showDirtyState 'false' git config prompt.showDirtyState 'false'
$GIT_PROMPT_INFO_FUNC $GIT_PROMPT_INFO_FUNC
fi
fi fi
fi
} }
TRAPINT () TRAPINT ()
{ {
__git_prompt_shortcircuit __git_prompt_shortcircuit
return $(( 128 + $1 )) return $(( 128 + $1 ))
} }
# sets a bunch of variables, see below: # sets a bunch of variables, see below:
_git_prompt__dirty_state () git_prompt__dirty_state ()
{ {
GIT_PROMPT_DIRTY_STATE_FRESH_REPO='' GIT_PROMPT_DIRTY_STATE_FRESH_REPO=''
GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='' GIT_PROMPT_DIRTY_STATE_INDEX_ADDED=''
GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='' GIT_PROMPT_DIRTY_STATE_INDEX_COPIED=''
GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='' GIT_PROMPT_DIRTY_STATE_INDEX_DELETED=''
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='' GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY=''
GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='' GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED=''
GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='' GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED=''
GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='' GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED=''
GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='' GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED=''
GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='' GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY=''
GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='' GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED=''
GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='' GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED=''
if [ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then if [[ "true" != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]]; then
return return
fi
local g="$(git_prompt__git_dir)"
if [[ -z "$g" ]]; then
return
fi
if [[ "$GIT_PROMPT_SHOWDIRTYSTATE" = 'off' ]]; then
return
fi
if [[ "$(git config --bool prompt.showDirtyState)" = "false" ]]; then
return
fi
GIT_PROMPT_DIRTY_STATE_FRESH_REPO='no'
GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='no'
GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='no'
GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='no'
GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='no'
GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='no'
GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='no'
if git rev-parse --quiet --verify HEAD >/dev/null; then
else
GIT_PROMPT_DIRTY_STATE_FRESH_REPO='yes'
fi
_big_repo='yes'
local line
while IFS=$'\n' read line; do
if [[ "$line" = M* ]]; then
GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
fi fi
if [[ "$line" = A* ]]; then
local g="$(_git_prompt__git_dir)" GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='yes'
if [ -z "$g" ]; then GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
return
fi fi
if [ "$GIT_PROMPT_SHOWDIRTYSTATE" = 'off' ]; then if [[ "$line" = R* ]]; then
return GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
fi fi
if [ "$(git config --bool prompt.showDirtyState)" = "false" ]; then if [[ "$line" = C* ]]; then
return GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
fi fi
if [[ "$line" = D* ]]; then
GIT_PROMPT_DIRTY_STATE_FRESH_REPO='no' GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='no' GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='no'
GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='no'
GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='no'
GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='no'
GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='no'
GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='no'
GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='no'
if git rev-parse --quiet --verify HEAD >/dev/null; then
else
GIT_PROMPT_DIRTY_STATE_FRESH_REPO='yes'
fi fi
_big_repo='yes' if [[ "$line" = \?\?* ]]; then
local line GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes'
while IFS=$'\n' read line; do fi
if [[ "$line" = M* ]]; then if [[ "$line" = ?M* ]]; then
GIT_PROMPT_DIRTY_STATE_INDEX_MODIFIED='yes' GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes'
fi fi
if [[ "$line" = A* ]]; then if [[ "$line" = ?D* ]]; then
GIT_PROMPT_DIRTY_STATE_INDEX_ADDED='yes' GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes'
fi fi
if [[ "$line" = R* ]]; then
GIT_PROMPT_DIRTY_STATE_INDEX_RENAMED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
fi
if [[ "$line" = C* ]]; then
GIT_PROMPT_DIRTY_STATE_INDEX_COPIED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
fi
if [[ "$line" = D* ]]; then
GIT_PROMPT_DIRTY_STATE_INDEX_DELETED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
fi
if [[ "$line" = \?\?* ]]; then
GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED='yes'
fi
if [[ "$line" = ?M* ]]; then
GIT_PROMPT_DIRTY_STATE_WORKTREE_MODIFIED='yes'
GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes'
fi
if [[ "$line" = ?D* ]]; then
GIT_PROMPT_DIRTY_STATE_WORKTREE_DELETED='yes'
GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY='yes'
fi
if [[ "$line" = UU* ]]; then if [[ "$line" = UU* ]]; then
GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='yes' GIT_PROMPT_DIRTY_STATE_INDEX_UNMERGED='yes'
GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes' GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY='yes'
fi fi
done < <(git status --porcelain 2> /dev/null) done < <(git status --porcelain 2> /dev/null)
_big_repo='' _big_repo=''
} }
#------------------ Fast Prompt ------------------ #------------------ Fast Prompt ------------------
@ -518,25 +518,25 @@ _git_prompt_info
_git_prompt__precmd_update_git_vars() _git_prompt__precmd_update_git_vars()
{ {
if [[ $ZSH_VERSION = *\ 4.2* ]]; then if [[ $ZSH_VERSION = *\ 4.2* ]]; then
# some older versions of zsh don't have periodic_functions, so do the # some older versions of zsh don't have periodic_functions, so do the
# slow path if that's the case: # slow path if that's the case:
$GIT_PROMPT_INFO_FUNC $GIT_PROMPT_INFO_FUNC
elif [ -n "$__EXECUTED_GIT_COMMAND" ]; then elif [[ -n "$__EXECUTED_GIT_COMMAND" ]]; then
$GIT_PROMPT_INFO_FUNC $GIT_PROMPT_INFO_FUNC
unset __EXECUTED_GIT_COMMAND unset __EXECUTED_GIT_COMMAND
fi fi
} }
_git_prompt__preexec_update_git_vars () _git_prompt__preexec_update_git_vars ()
{ {
case "$1" in case "$1" in
$EDITOR*) __EXECUTED_GIT_COMMAND=1 ;; $EDITOR*) __EXECUTED_GIT_COMMAND=1 ;;
g*) __EXECUTED_GIT_COMMAND=1 ;; g*) __EXECUTED_GIT_COMMAND=1 ;;
rm*) __EXECUTED_GIT_COMMAND=1 ;; rm*) __EXECUTED_GIT_COMMAND=1 ;;
touch*) __EXECUTED_GIT_COMMAND=1 ;; touch*) __EXECUTED_GIT_COMMAND=1 ;;
mkdir*) __EXECUTED_GIT_COMMAND=1 ;; mkdir*) __EXECUTED_GIT_COMMAND=1 ;;
esac esac
} }
#-------------------------------------------------- #--------------------------------------------------

@ -48,34 +48,34 @@ fi
# git prompt info: # git prompt info:
# The git prompt plugin will cause $GIT_PROMPT_INFO_FUNC to be called # The git prompt plugin will cause $GIT_PROMPT_INFO_FUNC to be called
# when $__GIT_PROMPT_INFO needs to be updated. # when $_GIT_PROMPT_INFO needs to be updated.
GIT_PROMPT_INFO_FUNC="update__GIT_PROMPT_INFO" GIT_PROMPT_INFO_FUNC="update__GIT_PROMPT_INFO"
GIT_PROMPT_SHOWUPSTREAM="verbose" GIT_PROMPT_SHOWUPSTREAM="verbose"
GIT_PROMPT_SHORTCIRCUIT='on' GIT_PROMPT_SHORTCIRCUIT='on'
local __GIT_PROMPT_INFO='' local _GIT_PROMPT_INFO=''
# will set __GIT_PROMPT_INFO # will set _GIT_PROMPT_INFO
update__GIT_PROMPT_INFO () update__GIT_PROMPT_INFO ()
{ {
local g="$(_git_prompt__git_dir)" local g="$(git_prompt__git_dir)"
if [ -z "$g" ]; then if [ -z "$g" ]; then
__GIT_PROMPT_INFO='' _GIT_PROMPT_INFO=''
return return
fi fi
_git_prompt__stash git_prompt__stash
local s=$GIT_PROMPT_STASH_STATE_DIRTY local s=$GIT_PROMPT_STASH_STATE_DIRTY
_git_prompt__upstream git_prompt__upstream
local p=$GIT_PROMPT_UPSTREAM_STATE local p=$GIT_PROMPT_UPSTREAM_STATE
_git_prompt__branch git_prompt__branch
local b=$GIT_PROMPT_BRANCH local b=$GIT_PROMPT_BRANCH
_git_prompt__rebase_info git_prompt__rebase_info
local r=$GIT_PROMPT_REBASE_INFO local r=$GIT_PROMPT_REBASE_INFO
_git_prompt__dirty_state git_prompt__dirty_state
local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY local w=$GIT_PROMPT_DIRTY_STATE_WORKTREE_DIRTY
local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY local i=$GIT_PROMPT_DIRTY_STATE_INDEX_DIRTY
local u=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED local u=$GIT_PROMPT_DIRTY_STATE_WORKTREE_UNTRACKED
@ -83,7 +83,7 @@ update__GIT_PROMPT_INFO ()
if [ -z "$b$i$w$u" ]; then if [ -z "$b$i$w$u" ]; then
if [ -n "$g" ]; then if [ -n "$g" ]; then
__GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$g dir)$R" _GIT_PROMPT_INFO="$R$_Cerror_(Error: bad ./$g dir)$R"
return return
fi fi
fi fi
@ -129,7 +129,7 @@ update__GIT_PROMPT_INFO ()
_prompt="($_prompt$)" _prompt="($_prompt$)"
fi fi
__GIT_PROMPT_INFO="$R$_prompt$R" _GIT_PROMPT_INFO="$R$_prompt$R"
} }
@ -140,7 +140,7 @@ local host_="%(!.$_Chost_root_.$_Chost_)%m$R"
local path_="%(!.$_Cpath_root_.$_Cpath_)%~$R" local path_="%(!.$_Cpath_root_.$_Cpath_)%~$R"
local jobs_="%(1j.$_Cjobs_%j$R.)" local jobs_="%(1j.$_Cjobs_%j$R.)"
PROMPT='$user_$host_$path_ $__GIT_PROMPT_INFO$jobs_# ' PROMPT='$user_$host_$path_ $_GIT_PROMPT_INFO$jobs_# '
local date_format_='%D{%a %b %d}, %*' local date_format_='%D{%a %b %d}, %*'
local date_="${_Cdate_}[$date_format_]$R" local date_="${_Cdate_}[$date_format_]$R"

Loading…
Cancel
Save