diff options
Diffstat (limited to 'Misc/vcs_info-examples')
-rw-r--r-- | Misc/vcs_info-examples | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples index 58dd8cf98..456b3a85b 100644 --- a/Misc/vcs_info-examples +++ b/Misc/vcs_info-examples @@ -212,6 +212,41 @@ function +vi-git-remotebranch() { } +### Derive hook names dynamically +# With the following line: +zstyle -e ':vcs_info:git+set-message:*' hooks 'reply=( ${${(k)functions[(I)[+]vi-git-set-message*]}#+vi-} )' +# Any function named `+vi-git-set-message-<anything>' would be automatically +# registered as a hook. For example: ++vi-git-set-message-foo() {} ++vi-git-set-message-bar() {} +# Both of these functions would be called, even if they are defined after the zstyle is set. + + +## git: Display pertinent environment variables +# If environment variables such as $GIT_DIR, $GIT_WORK_TREE, etc are set in the +# environment, they'll be shown in the value of the %m expando. +# +# Note that the %m expando is not used by default. To see a change, either change +# `[misc]' to `[branch]', or set the `formats` style to a value that includes `%m'. +zstyle ':vcs_info:git+post-backend:*' hooks git-post-backend-envvars ++vi-git-post-backend-envvars() { + local param + # This uses the ${parameters} special variable (provided by the zsh/parameter + # module), in conjunction with the parameter expansion flags ${(k)foo} and + # ${(M)foo:#pattern} (documented in "Parameter Expansion" in zshexpn(1)) + # and the (R) subscript flag (documented in "Subscript Flags" in zshparam(1)), + # to iterate over the names of all environment variables named "GIT_*". Then + # it uses the ${(P)foo} parameter expansion flag to show the values of those + # parameters. + # + # The value of ${hook_com[misc]} is substituted for %m in the values of the + # 'formats' and 'actionformats' styles. + for param in ${(Mk)parameters[(R)*export*]:#GIT_*}; do + hook_com[misc]+=";%U${param//'%'/%%}%u=%F{white}${${(P)param}//'%'/%%}%f" + done +} + + ### hg: Show marker when the working directory is not on a branch head # This may indicate that running `hg up` will do something # NOTE: the branchheads.cache file is not updated with every Mercurial @@ -433,8 +468,16 @@ zstyle ':vcs_info:-quilt-.quilt-standalone:*:*' quilt-patch-dir debian/patches # and so we want addon mode to also use a $QUILT_PATCHES value of # `debian/patches' in some directories. In the other directories we never # want the default `patches' though but a dedicated place for them. -# Say `~/patches/<repository-name>'. Now we'll use some evaluated-style -# magic to achieve all that: +# Say `~/patches/<repository-name>'. +# +# First of all, even without any configuration, vcs_info will do the right +# thing most of the time. Whenever quilt has already run in a directory, +# vcs_info will figure out whether that directory uses `patches' or +# `debian/patches' by interrogating metadata in the `.pc/' subdirectory, +# which quilt creates. To make vcs_info find the patches dir correctly even +# when the `.pc/' directory doesn't exist, read on. +# +# We'll use some evaluated-style magic to achieve that: zstyle -e ':vcs_info:*.quilt-addon:*:*' quilt-patch-dir 'my-patches-func' # That runs something called `my-patches-func', and the value of $reply is @@ -451,19 +494,17 @@ function my-patches-func() { fi # Now the part about the dedicated directory is a little trickier. - # It requires some knowledge of vcs_info's internals. Not much though. - # Everything about this is described in the manual because this - # variable (plus a few others) may be of interest in hooks, where - # they are available, too. - # - # The variable in question here is `$rrn' which is an abbreviation - # of repository-root-name. if you're in + # The variable in question here is `$context', which is the zstyle + # context used for lookups. Its last component is the repository-root-name, + # or ${rrn} for short. If you're in # /usr/src/zsh/Functions # and the repository being # /usr/src/zsh - # then the value of `$rrn' is `zsh'. Now in case the variable is - # empty (it shouldn't at this point, but you never know), let's - # drop back to quilt's default "patches". + # then the value of `$rrn' would be `zsh'. + local rrn=${context##*:} + + # Now, in case the variable is empty (it shouldn't at this point, but you + # never know), let's drop back to quilt's default value, "patches". if [[ -z ${rrn} ]]; then reply=( patches ) return 0 |