summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Shahaf <danielsh@apache.org>2019-12-02 01:54:17 +0000
committerDaniel Shahaf <danielsh@apache.org>2019-12-02 01:54:24 +0000
commit27a64a16fb5407c64ff190f2af5182797ac048a8 (patch)
treed1dffc3ac4a1e3829783617c602ff67a83e0c467
parenta833fe4a18526b76b447e107233541e6e6596968 (diff)
downloadzsh-27a64a16fb5407c64ff190f2af5182797ac048a8.tar.gz
zsh-27a64a16fb5407c64ff190f2af5182797ac048a8.tar.xz
zsh-27a64a16fb5407c64ff190f2af5182797ac048a8.zip
unposted: vcs_info: Add an example of using $functions to find hooks by name.
-rw-r--r--ChangeLog5
-rw-r--r--Misc/vcs_info-examples10
2 files changed, 15 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index c68c8e05c..470d454dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2019-12-02  Daniel Shahaf  <danielsh@apache.org>
+
+	* unposted: Misc/vcs_info-examples: vcs_info: Add an example
+	of using $functions to find hooks by name.
+
 2019-12-01  Oliver Kiddle  <okiddle@yahoo.co.uk>
 
 	* unposted: Completion/Unix/Command/_killall: another place
diff --git a/Misc/vcs_info-examples b/Misc/vcs_info-examples
index 58dd8cf98..c46fad93a 100644
--- a/Misc/vcs_info-examples
+++ b/Misc/vcs_info-examples
@@ -212,6 +212,16 @@ 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.
+
+
 ### 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