From: Vincent Bernat Date: Sun, 3 Aug 2014 10:31:44 +0000 (+0200) Subject: zsh: add ZSH completion X-Git-Tag: 0.7.11~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0a735dedbdf73c5ab50c60408cc57fa7f2204c09;p=thirdparty%2Flldpd.git zsh: add ZSH completion --- diff --git a/src/client/Makefile.am b/src/client/Makefile.am index ca83f354..f7305db3 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -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 index 00000000..9f7a98a8 --- /dev/null +++ b/src/client/_lldpcli @@ -0,0 +1,40 @@ +#compdef lldpcli +# +# zsh completion for lldpcli +# +# Copyright (c) 2014 Vincent Bernat +# +# 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 "$@"