summary refs log tree commit diff
path: root/Completion/Zsh/Function/_add-zle-hook-widget
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2016-07-20 06:54:21 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2016-07-22 06:23:39 +0000
commit5c7d92bd9c811404abe9784bdc18d129e5fbbdeb (patch)
treecbbc62d7bb50d1cdff5b05ed90a20bffab6aa8aa /Completion/Zsh/Function/_add-zle-hook-widget
parent82119d8d1723667ddc77d760d2be448beef7c972 (diff)
downloadzsh-5c7d92bd9c811404abe9784bdc18d129e5fbbdeb.tar.gz
zsh-5c7d92bd9c811404abe9784bdc18d129e5fbbdeb.tar.xz
zsh-5c7d92bd9c811404abe9784bdc18d129e5fbbdeb.zip
38890: _add-zle-hook-widget: New completion.
Diffstat (limited to 'Completion/Zsh/Function/_add-zle-hook-widget')
-rw-r--r--Completion/Zsh/Function/_add-zle-hook-widget36
1 files changed, 36 insertions, 0 deletions
diff --git a/Completion/Zsh/Function/_add-zle-hook-widget b/Completion/Zsh/Function/_add-zle-hook-widget
new file mode 100644
index 000000000..da65dd6e9
--- /dev/null
+++ b/Completion/Zsh/Function/_add-zle-hook-widget
@@ -0,0 +1,36 @@
+#compdef add-zle-hook-widget
+
+_add-zle-hook-widget_types() {
+  local -a tmp
+
+  autoload -U add-zle-hook-widget
+  add-zle-hook-widget -h > /dev/null # sets the zstyle
+  zstyle -g tmp zle-hook types
+
+  compadd "$@" -M 'L:|=zle-' -M 'r:|-=* r:|=*' -- zle-${^tmp}
+}
+
+_add-zle-hook-widget_widgets() {
+  if (( $+opt_args[-d] )); then
+    local -a tmp
+    zstyle -g tmp $line[1] widgets
+    _wanted widgets expl "installed hook" compadd -- ${tmp#<->:} && return 0
+  else
+    local -a user_widgets=( ${(k)widgets[(R)user:*]} )
+    _wanted widgets expl widget compadd -M 'r:|-=* r:|=*' -a user_widgets && return 0
+  fi
+  return 1
+}
+
+_add-zle-hook-widget() {
+  local context state state_descr line
+  typeset -A opt_args
+  _arguments -s -w -S : \
+    '(-D)-d[remove HOOK from the array]' \
+    '(-d)-D[interpret HOOK as pattern to remove from the array]' \
+    {-U,-z,-k}"[passed to 'autoload']" \
+    ':hook type:_add-zle-hook-widget_types' \
+    ':widget:_add-zle-hook-widget_widgets'
+}
+
+_add-zle-hook-widget "$@"