about summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2010-02-16 10:47:06 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2010-02-16 10:47:06 +0000
commit4523ff9383b93360f8031050061fe9e7fabde34a (patch)
treed87584450043778ca5f0d762a260bf16d49ffa0e /Functions
parent94777f64e8963b5418ce86c8e8bb51ad7094587e (diff)
downloadzsh-4523ff9383b93360f8031050061fe9e7fabde34a.tar.gz
zsh-4523ff9383b93360f8031050061fe9e7fabde34a.tar.xz
zsh-4523ff9383b93360f8031050061fe9e7fabde34a.zip
Frank Terbeck, Seth House: 27712, 22713, 27714:
VCS Info hooks and Mercurial improvements
Diffstat (limited to 'Functions')
-rw-r--r--Functions/VCS_Info/.distfiles1
-rw-r--r--Functions/VCS_Info/VCS_INFO_hook42
2 files changed, 43 insertions, 0 deletions
diff --git a/Functions/VCS_Info/.distfiles b/Functions/VCS_Info/.distfiles
index 879aa1eda..cde11b26c 100644
--- a/Functions/VCS_Info/.distfiles
+++ b/Functions/VCS_Info/.distfiles
@@ -6,6 +6,7 @@ VCS_INFO_bydir_detect
 VCS_INFO_check_com
 VCS_INFO_formats
 VCS_INFO_get_cmd
+VCS_INFO_hook
 vcs_info_lastmsg
 VCS_INFO_maxexports
 VCS_INFO_nvcsformats
diff --git a/Functions/VCS_Info/VCS_INFO_hook b/Functions/VCS_Info/VCS_INFO_hook
new file mode 100644
index 000000000..71845d808
--- /dev/null
+++ b/Functions/VCS_Info/VCS_INFO_hook
@@ -0,0 +1,42 @@
+### vim:ft=zsh:foldmethod=marker
+## Written by Frank Terbeck <ft@bewatermyfriend.org>
+## Distributed under the same BSD-ish license as zsh itself.
+
+local hook func
+local -x context hook_name
+local -xi ret
+local -a hooks
+local -i debug
+
+ret=0
+hook_name="$1"
+shift
+context=":vcs_info:${vcs}+${hook_name}:${usercontext}:${rrn}"
+
+zstyle -t "${context}" debug && debug=1 || debug=0
+if (( debug )); then
+    printf 'VCS_INFO_hook: running hook: "%s"\n' "${hook_name}"
+    printf 'VCS_INFO_hook: current context: "%s"\n' "${context}"
+fi
+
+zstyle -a "${context}" hooks hooks || return 0
+# protect some internal variables in hooks
+typeset -r vcs rrn usercontext maxexports msgs vcs_comm
+for hook in ${hooks} ; do
+    func="+vi-${hook}"
+    if (( ${+functions[$func]} == 0 )); then
+        (( debug )) && printf '  + Unknown function: "%s"\n' "${func}"
+        continue
+    fi
+    (( debug )) && printf '  + Running function: "%s"\n' "${func}"
+    ${func} "$@"
+    case $? in
+        (0)
+            ;;
+        (*)
+            break
+            ;;
+    esac
+done
+typeset +r vcs rrn usercontext maxexports msgs vcs_comm
+return $ret