From 8feaef57405a0c576809dd0cfd3d77595c20070a Mon Sep 17 00:00:00 2001 From: Steve Durrheimer Date: Sat, 9 Apr 2016 18:19:31 +0200 Subject: [PATCH] Add zsh completion for 'docker volume ls -f {dangling,driver,name}' Signed-off-by: Steve Durrheimer --- contrib/completion/zsh/_docker | 46 +++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/contrib/completion/zsh/_docker b/contrib/completion/zsh/_docker index 2eb673fe1f..25f53c53e1 100644 --- a/contrib/completion/zsh/_docker +++ b/contrib/completion/zsh/_docker @@ -138,6 +138,17 @@ __docker_containers_names() { __docker_get_containers all names "$@" } +__docker_plugins() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + emulate -L zsh + setopt extendedglob + local -a plugins + plugins=(${(ps: :)${(M)${(f)${${"$(_call_program commands docker $docker_options info)"##*$'\n'Plugins:}%%$'\n'^ *}}:# $1: *}## $1: }) + _describe -t plugins "$1 plugins" plugins && ret=0 + return ret +} + __docker_images() { [[ $PREFIX = -* ]] && return 1 integer ret=1 @@ -427,6 +438,34 @@ __docker_network_subcommand() { return ret } +__docker_volume_complete_ls_filters() { + [[ $PREFIX = -* ]] && return 1 + integer ret=1 + + if compset -P '*='; then + case "${${words[-1]%=*}#*=}" in + (dangling) + dangling_opts=('true' 'false') + _describe -t dangling-filter-opts "Dangling Filter Options" dangling_opts && ret=0 + ;; + (driver) + __docker_plugins Volume && ret=0 + ;; + (name) + __docker_volumes && ret=0 + ;; + *) + _message 'value' && ret=0 + ;; + esac + else + opts=('dangling' 'driver' 'name') + _describe -t filter-opts "Filter Options" opts -qS "=" && ret=0 + fi + + return ret +} + __docker_volumes() { [[ $PREFIX = -* ]] && return 1 integer ret=1 @@ -495,8 +534,13 @@ __docker_volume_subcommand() { (ls) _arguments $(__docker_arguments) \ $opts_help \ - "($help)*"{-f=,--filter=}"[Provide filter values (i.e. 'dangling=true')]:filter: " \ + "($help)*"{-f=,--filter=}"[Provide filter values]:filter:->filter-options" \ "($help -q --quiet)"{-q,--quiet}"[Only display volume names]" && ret=0 + case $state in + (filter-options) + __docker_volume_complete_ls_filters && ret=0 + ;; + esac ;; (rm) _arguments $(__docker_arguments) \