123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- __git_printf_supports_v=
- printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
-
-
-
- __git_ps1_show_upstream ()
- {
- local key value
- local svn_remote svn_url_pattern count n
- local upstream=git legacy="" verbose="" name=""
-
- svn_remote=()
-
- local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
- while read -r key value; do
- case "$key" in
- bash.showupstream)
- GIT_PS1_SHOWUPSTREAM="$value"
- if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
- p=""
- return
- fi
- ;;
- svn-remote.*.url)
- svn_remote[$((${#svn_remote[@]} + 1))]="$value"
- svn_url_pattern="$svn_url_pattern\\|$value"
- upstream=svn+git
- ;;
- esac
- done <<< "$output"
-
-
- for option in ${GIT_PS1_SHOWUPSTREAM}; do
- case "$option" in
- git|svn) upstream="$option" ;;
- verbose) verbose=1 ;;
- legacy) legacy=1 ;;
- name) name=1 ;;
- esac
- done
-
-
- case "$upstream" in
- git) upstream="@{upstream}" ;;
- svn*)
-
-
- local -a svn_upstream
- svn_upstream=($(git log --first-parent -1 \
- --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
- if [[ 0 -ne ${#svn_upstream[@]} ]]; then
- svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
- svn_upstream=${svn_upstream%@*}
- local n_stop="${#svn_remote[@]}"
- for ((n=1; n <= n_stop; n++)); do
- svn_upstream=${svn_upstream#${svn_remote[$n]}}
- done
-
- if [[ -z "$svn_upstream" ]]; then
-
- upstream=${GIT_SVN_ID:-git-svn}
- else
- upstream=${svn_upstream#/}
- fi
- elif [[ "svn+git" = "$upstream" ]]; then
- upstream="@{upstream}"
- fi
- ;;
- esac
-
-
- if [[ -z "$legacy" ]]; then
- count="$(git rev-list --count --left-right \
- "$upstream"...HEAD 2>/dev/null)"
- else
-
- local commits
- if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
- then
- local commit behind=0 ahead=0
- for commit in $commits
- do
- case "$commit" in
- "<"*) ((behind++)) ;;
- *) ((ahead++)) ;;
- esac
- done
- count="$behind $ahead"
- else
- count=""
- fi
- fi
-
-
- if [[ -z "$verbose" ]]; then
- case "$count" in
- "")
- p="" ;;
- "0 0")
- p="=" ;;
- "0 "*)
- p=">" ;;
- *" 0")
- p="<" ;;
- *)
- p="<>" ;;
- esac
- else
- case "$count" in
- "")
- p="" ;;
- "0 0")
- p=" u=" ;;
- "0 "*)
- p=" u+${count#0 }" ;;
- *" 0")
- p=" u-${count% 0}" ;;
- *)
- p=" u+${count#* }-${count% *}" ;;
- esac
- if [[ -n "$count" && -n "$name" ]]; then
- __git_ps1_upstream_name=$(git rev-parse \
- --abbrev-ref "$upstream" 2>/dev/null)
- if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
- p="$p \${__git_ps1_upstream_name}"
- else
- p="$p ${__git_ps1_upstream_name}"
-
-
- unset __git_ps1_upstream_name
- fi
- fi
- fi
-
- }
-
-
-
-
- __git_ps1_colorize_gitstring ()
- {
- if [[ -n ${ZSH_VERSION-} ]]; then
- local c_red='%F{red}'
- local c_green='%F{green}'
- local c_lblue='%F{blue}'
- local c_clear='%f'
- else
-
-
- local c_red='\[\e[31m\]'
- local c_green='\[\e[32m\]'
- local c_lblue='\[\e[1;34m\]'
- local c_clear='\[\e[0m\]'
- fi
- local bad_color=$c_red
- local ok_color=$c_green
- local flags_color="$c_lblue"
-
- local branch_color=""
- if [ $detached = no ]; then
- branch_color="$ok_color"
- else
- branch_color="$bad_color"
- fi
- c="$branch_color$c"
-
- z="$c_clear$z"
- if [ "$w" = "*" ]; then
- w="$bad_color$w"
- fi
- if [ -n "$i" ]; then
- i="$ok_color$i"
- fi
- if [ -n "$s" ]; then
- s="$flags_color$s"
- fi
- if [ -n "$u" ]; then
- u="$bad_color$u"
- fi
- r="$c_clear$r"
- }
-
- __git_eread ()
- {
- local f="$1"
- shift
- test -r "$f" && read "$@" <"$f"
- }
-
-
-
-
-
-
-
-
-
-
-
-
- __git_ps1 ()
- {
-
- local exit=$?
- local pcmode=no
- local detached=no
- local ps1pc_start='\u@\h:\w '
- local ps1pc_end='\$ '
- local printf_format=' (%s)'
-
- case "$#" in
- 2|3) pcmode=yes
- ps1pc_start="$1"
- ps1pc_end="$2"
- printf_format="${3:-$printf_format}"
-
-
-
- PS1="$ps1pc_start$ps1pc_end"
- ;;
- 0|1) printf_format="${1:-$printf_format}"
- ;;
- *) return $exit
- ;;
- esac
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- local ps1_expanded=yes
- [ -z "$ZSH_VERSION" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
- [ -z "$BASH_VERSION" ] || shopt -q promptvars || ps1_expanded=no
-
- local repo_info rev_parse_exit_code
- repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
- --is-bare-repository --is-inside-work-tree \
- --short HEAD 2>/dev/null)"
- rev_parse_exit_code="$?"
-
- if [ -z "$repo_info" ]; then
- return $exit
- fi
-
- local short_sha
- if [ "$rev_parse_exit_code" = "0" ]; then
- short_sha="${repo_info##*$'\n'}"
- repo_info="${repo_info%$'\n'*}"
- fi
- local inside_worktree="${repo_info##*$'\n'}"
- repo_info="${repo_info%$'\n'*}"
- local bare_repo="${repo_info##*$'\n'}"
- repo_info="${repo_info%$'\n'*}"
- local inside_gitdir="${repo_info##*$'\n'}"
- local g="${repo_info%$'\n'*}"
-
- if [ "true" = "$inside_worktree" ] &&
- [ -n "${GIT_PS1_HIDE_IF_PWD_IGNORED-}" ] &&
- [ "$(git config --bool bash.hideIfPwdIgnored)" != "false" ] &&
- git check-ignore -q .
- then
- return $exit
- fi
-
- local r=""
- local b=""
- local step=""
- local total=""
- if [ -d "$g/rebase-merge" ]; then
- __git_eread "$g/rebase-merge/head-name" b
- __git_eread "$g/rebase-merge/msgnum" step
- __git_eread "$g/rebase-merge/end" total
- if [ -f "$g/rebase-merge/interactive" ]; then
- r="|REBASE-i"
- else
- r="|REBASE-m"
- fi
- else
- if [ -d "$g/rebase-apply" ]; then
- __git_eread "$g/rebase-apply/next" step
- __git_eread "$g/rebase-apply/last" total
- if [ -f "$g/rebase-apply/rebasing" ]; then
- __git_eread "$g/rebase-apply/head-name" b
- 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/REVERT_HEAD" ]; then
- r="|REVERTING"
- elif [ -f "$g/BISECT_LOG" ]; then
- r="|BISECTING"
- fi
-
- if [ -n "$b" ]; then
- :
- elif [ -h "$g/HEAD" ]; then
-
- b="$(git symbolic-ref HEAD 2>/dev/null)"
- else
- local head=""
- if ! __git_eread "$g/HEAD" head; then
- return $exit
- fi
-
- b="${head#ref: }"
- if [ "$head" = "$b" ]; then
- detached=yes
- b="$(
- case "${GIT_PS1_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="$short_sha..."
- b="($b)"
- fi
- fi
- fi
-
- if [ -n "$step" ] && [ -n "$total" ]; then
- r="$r $step/$total"
- fi
-
- local w=""
- local i=""
- local s=""
- local u=""
- local c=""
- local p=""
-
- if [ "true" = "$inside_gitdir" ]; then
- if [ "true" = "$bare_repo" ]; then
- c="BARE:"
- else
- b="GIT_DIR!"
- fi
- elif [ "true" = "$inside_worktree" ]; then
- if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
- [ "$(git config --bool bash.showDirtyState)" != "false" ]
- then
- git diff --no-ext-diff --quiet --exit-code || w="*"
- if [ -n "$short_sha" ]; then
- git diff-index --cached --quiet HEAD -- || i="+"
- else
- i="#"
- fi
- fi
- if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
- git rev-parse --verify --quiet refs/stash >/dev/null
- then
- s="$"
- fi
-
- if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
- [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
- git ls-files --others --exclude-standard --error-unmatch -- ':/*' >/dev/null 2>/dev/null
- then
- u="%${ZSH_VERSION+%}"
- fi
-
- if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
- __git_ps1_show_upstream
- fi
- fi
-
- local z="${GIT_PS1_STATESEPARATOR-" "}"
-
-
- if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
- __git_ps1_colorize_gitstring
- fi
-
- b=${b##refs/heads/}
- if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
- __git_ps1_branch_name=$b
- b="\${__git_ps1_branch_name}"
- fi
-
- local f="$w$i$s$u"
- local gitstring="$c$b${f:+$z$f}$r$p"
-
- if [ $pcmode = yes ]; then
- if [ "${__git_printf_supports_v-}" != yes ]; then
- gitstring=$(printf -- "$printf_format" "$gitstring")
- else
- printf -v gitstring -- "$printf_format" "$gitstring"
- fi
- PS1="$ps1pc_start$gitstring$ps1pc_end"
- else
- printf -- "$printf_format" "$gitstring"
- fi
-
- return $exit
- }
|