1## vim:ft=zsh 2## Written by Frank Terbeck <ft@bewatermyfriend.org> 3## Distributed under the same BSD-ish license as zsh itself. 4 5setopt localoptions noksharrays NO_shwordsplit 6local msg tmp 7local -i i 8local -xA hook_com 9# The _origs are needed because hooks can change values and there would 10# be no way to get the originals back for later hooks (a hook is run for 11# each message, that's being created). 12hook_com=( 13 action "$1" 14 action_orig "$1" 15 branch "$2" 16 branch_orig "$2" 17 base "$3" 18 base_orig "$3" 19 staged "$4" 20 staged_orig "$4" 21 unstaged "$5" 22 unstaged_orig "$5" 23 revision "$6" 24 revision_orig "$6" 25 misc "$7" 26 misc_orig "$7" 27 vcs "${vcs}" 28 vcs_orig "${vcs}" 29) 30hook_com[base-name]="${${hook_com[base]}:t}" 31hook_com[base-name_orig]="${hook_com[base_name]}" 32hook_com[subdir]="$(VCS_INFO_reposub ${hook_com[base]})" 33hook_com[subdir_orig]="${hook_com[subdir]}" 34 35VCS_INFO_hook 'post-backend' 36 37## description: 38# action: a string that signals a certain non-default condition in the 39# repository (like 'rebase-i' in git). If this in non-empty, 40# the actionformats will be used, too. 41# branch: the name of the currently checked out branch. 42# base: the full name of the repository's root directory. 43# staged: non-empty if the repository contains staged changes. 44# unstaged: non-empty if the repository contains unstaged changes. 45# revision: an identifier of the currently checked out revision. 46# misc: a string that may contain anything the backend author likes. 47# 48# If an argument has no valid value for a given backend, an empty value 49# should be provided. eg: 50# VCS_INFO_formats '' "${foobranch}" "${foobase}" '' '' '' "${foomisc}" 51 52if [[ -n ${hook_com[action]} ]] ; then 53 zstyle -a ":vcs_info:${vcs}:${usercontext}:${rrn}" actionformats msgs 54 (( ${#msgs} < 1 )) && msgs[1]=' (%s)-[%b|%a]%u%c-' 55else 56 zstyle -a ":vcs_info:${vcs}:${usercontext}:${rrn}" formats msgs 57 (( ${#msgs} < 1 )) && msgs[1]=' (%s)-[%b]%u%c-' 58fi 59 60if [[ -n ${hook_com[staged]} ]] ; then 61 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" stagedstr tmp 62 [[ -z ${tmp} ]] && hook_com[staged]='S' || hook_com[staged]=${tmp} 63fi 64 65if [[ -n ${hook_com[unstaged]} ]] ; then 66 zstyle -s ":vcs_info:${vcs}:${usercontext}:${rrn}" unstagedstr tmp 67 [[ -z ${tmp} ]] && hook_com[unstaged]='U' || hook_com[unstaged]=${tmp} 68fi 69 70if [[ ${quiltmode} != 'standalone' ]] && VCS_INFO_hook "pre-addon-quilt"; then 71 local -x REPLY 72 VCS_INFO_quilt addon 73 hook_com[quilt]="${REPLY}" 74 unset REPLY 75elif [[ ${quiltmode} == 'standalone' ]]; then 76 hook_com[quilt]=${hook_com[misc]} 77fi 78 79(( ${#msgs} > maxexports )) && msgs[$(( maxexports + 1 )),-1]=() 80for i in {1..${#msgs}} ; do 81 if VCS_INFO_hook "set-message" $(( $i - 1 )) "${msgs[$i]}"; then 82 zformat -f msg ${msgs[$i]} \ 83 a:${hook_com[action]} \ 84 b:${hook_com[branch]} \ 85 c:${hook_com[staged]} \ 86 i:${hook_com[revision]} \ 87 m:${hook_com[misc]} \ 88 r:${hook_com[base-name]} \ 89 s:${hook_com[vcs]} \ 90 u:${hook_com[unstaged]} \ 91 Q:${hook_com[quilt]} \ 92 R:${hook_com[base]} \ 93 S:${hook_com[subdir]} 94 msgs[$i]=${msg} 95 else 96 msgs[$i]=${hook_com[message]} 97 fi 98done 99hook_com=() 100backend_misc=() 101return 0 102