]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
zsh: add ZSH completion
authorVincent Bernat <vincent@bernat.im>
Sun, 3 Aug 2014 10:31:44 +0000 (12:31 +0200)
committerVincent Bernat <vincent@bernat.im>
Sun, 3 Aug 2014 10:33:25 +0000 (12:33 +0200)
src/client/Makefile.am
src/client/_lldpcli [new file with mode: 0644]

index ca83f354e4ab047d19ce4e0cd676efd1e53d956c..f7305db3d7747b86fdf7824aeb02d707efe1374a 100644 (file)
@@ -40,5 +40,8 @@ lldpcli_CFLAGS  += @JSONC_CFLAGS@
 lldpcli_LDADD   += @JSONC_LIBS@
 endif
 
+# Completions
 bashcompletiondir = $(sysconfdir)/bash_completion.d
 bashcompletion_DATA = lldpcli.bash-completion
+zshcompletiondir = $(datadir)/zsh/vendor-completions
+zshcompletion_DATA = _lldpcli
diff --git a/src/client/_lldpcli b/src/client/_lldpcli
new file mode 100644 (file)
index 0000000..9f7a98a
--- /dev/null
@@ -0,0 +1,40 @@
+#compdef lldpcli
+#
+# zsh completion for lldpcli
+#
+# Copyright (c) 2014 Vincent Bernat <bernat@luffy.cx>
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+
+__lldpcli_command () {
+    local -a completions
+    completions=(${(f)"$(_call_program commands lldpcli complete ${words[1,$(($CURRENT-1))]})"})
+    completions=(${completions:s/ /:/})
+    _describe -t lldpcli-command "lldpcli completion" completions "$@"
+}
+
+_lldpcli () {
+    local curcontext="$curcontext" state line
+
+    _arguments -C \
+        '*-d[print more debugging information]' \
+        '(- *)-v[print version number and exit]' \
+        '-u[use an alternate socket with lldpd]:UNIX socket:_files' \
+        '-f[output format]:format:(plain xml json keyvalue)' \
+        '*-c[read a configuration file]:configuration file:_files' \
+        '(-)*::lldpcli command:__lldpcli_command'
+}
+
+
+_lldpcli "$@"