From ccb45b320124d17f4a2594e85c80c970bb0259ef Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Sun, 17 Jul 2016 12:24:08 +0200 Subject: 38837 (tweaked c.f. 38826): new virsh completion --- Completion/Unix/Command/_libvirt | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Completion/Unix/Command/_libvirt (limited to 'Completion/Unix/Command/_libvirt') diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt new file mode 100644 index 000000000..a9249b31e --- /dev/null +++ b/Completion/Unix/Command/_libvirt @@ -0,0 +1,55 @@ +#compdef virsh + +local curcontext="$curcontext" state line expl ret=1 + +case $service in + virsh) + if (( ! $+_cache_virsh_cmds )); then + _cache_virsh_cmds=( ${${${${(f):-"$(_call_program options virsh help)"}:#*:}/# ##}/ *} ) + fi + if (( ! $+_cache_virsh_cmdopts )); then + typeset -gA _cache_virsh_cmdopts + fi + _arguments -A "-*" -C -S -s -w \ + '(- *)'{-h,--help}'[print help information and exit]' \ + '(- *)'{-v,--version=short}'[print short version information and exit]' \ + '(- *)'{-V,--version=long}'[print long version information and exit]' \ + '(-c --connect)'{-c+,--connect}'[specify connection URI]:URI:_hosts' \ + '(-d --debug)'{-d+,--debug}'[set debug level]:level:(0 1 2 3 4)' \ + '(-e --escape)'{-e+,--escape}'[set escape sequence for console]:sequence' \ + '(-k --keepalive-interval)'{-k+,--keepalive-interval}'[set keepalive interval]:interval' \ + '(-K --keepalive-count)'{-K+,--keepalive-count}'[set keepalive count]:count' \ + '(-l --log)'{-l+,--log}'[specify log file]:file:_files' \ + '(-q --quiet)'{-q,--quiet}'[quiet mode]' \ + '(-r --readonly)'{-r,--readonly}'[connect readonly]' \ + '(-t --timing)'{-t,--timing}'[print timing information]' \ + '1:command:->virsh_cmds' \ + '*:cmdopt:->virsh_cmdopts' && return + # We accept only virsh command options after the first non-option argument + # (i.e., the virsh command itself), this makes it so with the -A "-*" above + [[ -z $state ]] && state=virsh_cmdopts + ;; +esac + +case $state in + virsh_cmds) + _wanted commands expl 'virsh command' compadd -a _cache_virsh_cmds && ret=0 + ;; + virsh_cmdopts) + local cmd + if [[ $words[-1] == /* || $words[-1] == ./* ]]; then + _default + return + fi + for (( i = 2; i <= $#words; i++ )); do + [[ -n "${_cache_virsh_cmds[(r)$words[$i]]}" ]] && cmd=$words[$i] && break + done + [[ -z $cmd ]] && return 1 + if [[ -z $_cache_virsh_cmdopts[$cmd] ]]; then + _cache_virsh_cmdopts[$cmd]=${(M)${${${${=${(f)"$(_call_program virsh virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + fi + _values -w options ${=_cache_virsh_cmdopts[$cmd]} && ret=0 + ;; +esac + +return ret -- cgit v1.2.3 From f117edfabebda4c21622ff38ea9e55bf01b2f8ab Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Thu, 21 Jul 2016 17:38:48 +0200 Subject: 38894: completion for virt-admin and libvirt client/server IDs/names --- ChangeLog | 5 ++ Completion/Unix/Command/_libvirt | 103 ++++++++++++++++++++++++++++++++++----- 2 files changed, 95 insertions(+), 13 deletions(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index dea9e2d84..3af6b342b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-07-21 Oliver Kiddle + + * 38894: Marko Myllynen: Completion/Unix/Command/_libvirt: + completion for virt-admin and libvirt client/server IDs/names + 2016-07-21 Felipe Sateler * 38901: Completion/Debian/Command/_schroot: Add -r/--run-session diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index a9249b31e..c855ac980 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -1,34 +1,84 @@ -#compdef virsh +#compdef virsh virt-admin virt-host-validate virt-pki-validate virt-xml-validate local curcontext="$curcontext" state line expl ret=1 +local exargs="-h --help -V -v --version=short --version=long" +local -a common_opts interact_cmds +common_opts=( + '(- *)'{-h,--help}'[print help information and exit]' + '(- *)'{-v,--version=short}'[print short version information and exit]' + '(- *)'{-V,--version=long}'[print long version information and exit]' + "(-c --connect $exargs)"{-c+,--connect=}'[specify connection URI]:URI:_hosts' + "(-d --debug -q --quiet $exargs)"{-d+,--debug=}'[set debug level]:level:(0 1 2 3 4)' + "(-l --log $exargs)"{-l+,--log=}'[specify log file]:file:_files' + "(-q --quiet -d --debug $exargs)"{-q,--quiet}'[quiet mode]' +) +interact_cmds=(cd echo exit quit connect) + case $service in virsh) if (( ! $+_cache_virsh_cmds )); then _cache_virsh_cmds=( ${${${${(f):-"$(_call_program options virsh help)"}:#*:}/# ##}/ *} ) + local icmd + for icmd in $interact_cmds; do + _cache_virsh_cmds[$_cache_virsh_cmds[(i)$icmd]]=() + done fi if (( ! $+_cache_virsh_cmdopts )); then typeset -gA _cache_virsh_cmdopts fi _arguments -A "-*" -C -S -s -w \ - '(- *)'{-h,--help}'[print help information and exit]' \ - '(- *)'{-v,--version=short}'[print short version information and exit]' \ - '(- *)'{-V,--version=long}'[print long version information and exit]' \ - '(-c --connect)'{-c+,--connect}'[specify connection URI]:URI:_hosts' \ - '(-d --debug)'{-d+,--debug}'[set debug level]:level:(0 1 2 3 4)' \ - '(-e --escape)'{-e+,--escape}'[set escape sequence for console]:sequence' \ - '(-k --keepalive-interval)'{-k+,--keepalive-interval}'[set keepalive interval]:interval' \ - '(-K --keepalive-count)'{-K+,--keepalive-count}'[set keepalive count]:count' \ - '(-l --log)'{-l+,--log}'[specify log file]:file:_files' \ - '(-q --quiet)'{-q,--quiet}'[quiet mode]' \ - '(-r --readonly)'{-r,--readonly}'[connect readonly]' \ - '(-t --timing)'{-t,--timing}'[print timing information]' \ + "$common_opts[@]" \ + "(-e --escape $exargs)"{-e+,--escape=}'[set escape sequence for console]:sequence' \ + "(-k --keepalive-interval $exargs)"{-k+,--keepalive-interval=}'[set keepalive interval]:interval' \ + "(-K --keepalive-count $exargs)"{-K+,--keepalive-count=}'[set keepalive count]:count' \ + "(-r --readonly $exargs)"{-r,--readonly}'[connect readonly]' \ + "(-t --timing $exargs)"{-t,--timing}'[print timing information]' \ '1:command:->virsh_cmds' \ '*:cmdopt:->virsh_cmdopts' && return # We accept only virsh command options after the first non-option argument # (i.e., the virsh command itself), this makes it so with the -A "-*" above [[ -z $state ]] && state=virsh_cmdopts ;; + virt-admin) + if (( ! $+_cache_virt_admin_cmds )); then + _cache_virt_admin_cmds=( ${${${${(f):-"$(_call_program options virt-admin help)"}:#*:}/# ##}/ *} ) + local icmd + for icmd in $interact_cmds; do + _cache_virt_admin_cmds[$_cache_virt_admin_cmds[(i)$icmd]]=() + done + fi + if (( ! $+_cache_virt_admin_cmdopts )); then + typeset -gA _cache_virt_admin_cmdopts + fi + _arguments -A "-*" -C -S -s -w \ + "$common_opts[@]" \ + '1:command:->virt_admin_cmds' \ + '*:cmdopt:->virt_admin_cmdopts' && return + # Same as with virsh above + [[ -z $state ]] && state=virt_admin_cmdopts + ;; + virt-host-validate) + _arguments -A "-*" -S \ + '(- *)'{-h,--help}'[print help information and exit]' \ + '(- *)'{-v,--version}'[print version information and exit]' \ + '(- *)'{-q,--quiet}'[quiet mode]' \ + '1:hv-type:(qemu lxc)' && return + ;; + virt-pki-validate) + _arguments -A "-*" -S \ + '(- *)'{-h,--help}'[print help information and exit]' \ + '(- *)'{-V,--version}'[print version information and exit]' \ + && return + ;; + virt-xml-validate) + _arguments -A "-*" -S \ + '(- *)'{-h,--help}'[print help information and exit]' \ + '(- *)'{-V,--version}'[print version information and exit]' \ + '1:file:_files -g "*.xml(-.)"' \ + '2:schema:(domainsnapshot domain network storagepool storagevol nodedev capability nwfilter secret interface)' \ + && return + ;; esac case $state in @@ -50,6 +100,33 @@ case $state in fi _values -w options ${=_cache_virsh_cmdopts[$cmd]} && ret=0 ;; + virt_admin_cmds) + _wanted commands expl 'virt-admin command' compadd -a _cache_virt_admin_cmds && ret=0 + ;; + virt_admin_cmdopts) + local cmd + for (( i = 2; i <= $#words; i++ )); do + [[ -n "${_cache_virt_admin_cmds[(r)$words[$i]]}" ]] && cmd=$words[$i] && break + done + [[ -z $cmd ]] && return 1 + if [[ $words[-2] == --server ]]; then + _values servers ${=${(S)${${(f)$(sudo virt-admin srv-list)}##*--- }//[0-9]* }} && return 0 + fi + if [[ $words[-2] == --client ]]; then + local srv + for (( i = 2; i <= $#words; i++ )); do + [[ $words[$i] == --server ]] && srv=$words[$i+1] && break + done + [[ -z $srv ]] && return 1 + _values servers ${=${${(f):-"$(sudo virt-admin srv-clients-list --server $srv)"}/ [a-z]*}//[^0-9]} && return 0 + fi + if [[ -z $_cache_virt_admin_cmdopts[$cmd] ]]; then + _cache_virt_admin_cmdopts[$cmd]=${(M)${${${${=${(f)"$(_call_program virt-admin virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + fi + [[ -n $_cache_virt_admin_cmdopts[$cmd] ]] && \ + _values -w options ${=_cache_virt_admin_cmdopts[$cmd]} && ret=0 + ;; + esac return ret -- cgit v1.2.3 From 4547897976f0f3cfe7180d85c92406d43e0b3763 Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Wed, 31 Aug 2016 16:34:41 +0200 Subject: 39118: (almost) complete virsh completions --- ChangeLog | 5 ++ Completion/Unix/Command/_libvirt | 153 +++++++++++++++++++++++++++++++-------- 2 files changed, 129 insertions(+), 29 deletions(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index 5a3763950..5480a57e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-08-31 Oliver Kiddle + + * Marko Myllynen: 39118: Completion/Unix/Command/_libvirt: + (almost) complete virsh completions + 2016-08-31 Peter Stephenson * 39141: Test/D04parameter.ztst: use zsh in SHLVL test to remove diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index c855ac980..4fb963011 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -1,6 +1,7 @@ #compdef virsh virt-admin virt-host-validate virt-pki-validate virt-xml-validate local curcontext="$curcontext" state line expl ret=1 +declare -A opt_args local exargs="-h --help -V -v --version=short --version=long" local -a common_opts interact_cmds @@ -15,17 +16,48 @@ common_opts=( ) interact_cmds=(cd echo exit quit connect) +typeset -A dom_opts +dom_opts=( + console " " + destroy " " + managedsave " " + reboot " " + reset " " + resume --state-paused + save " " + screenshot " " + send-key " " + shutdown --state-running + start --state-shutoff + suspend --state-running + ttyconsole " " + undefine --inactive + vncdisplay " " +) +typeset -A iface_opts +iface_opts=( + iface-start --inactive +) +typeset -A net_opts +net_opts=( + net-start --inactive +) +typeset -A pool_opts +pool_opts=( + pool-start --inactive +) + case $service in virsh) if (( ! $+_cache_virsh_cmds )); then - _cache_virsh_cmds=( ${${${${(f):-"$(_call_program options virsh help)"}:#*:}/# ##}/ *} ) + _cache_virsh_cmds=( ${${${${(f):-"$(_call_program commands virsh help)"}:#*:}/# ##}/ *} ) local icmd for icmd in $interact_cmds; do _cache_virsh_cmds[$_cache_virsh_cmds[(i)$icmd]]=() done fi - if (( ! $+_cache_virsh_cmdopts )); then - typeset -gA _cache_virsh_cmdopts + if (( ! $+_cache_virsh_cmd_opts )); then + typeset -gA _cache_virsh_cmd_opts fi _arguments -A "-*" -C -S -s -w \ "$common_opts[@]" \ @@ -35,28 +67,28 @@ case $service in "(-r --readonly $exargs)"{-r,--readonly}'[connect readonly]' \ "(-t --timing $exargs)"{-t,--timing}'[print timing information]' \ '1:command:->virsh_cmds' \ - '*:cmdopt:->virsh_cmdopts' && return + '*:cmdopt:->virsh_cmd_opts' && return # We accept only virsh command options after the first non-option argument # (i.e., the virsh command itself), this makes it so with the -A "-*" above - [[ -z $state ]] && state=virsh_cmdopts + [[ -z $state ]] && state=virsh_cmd_opts ;; virt-admin) if (( ! $+_cache_virt_admin_cmds )); then - _cache_virt_admin_cmds=( ${${${${(f):-"$(_call_program options virt-admin help)"}:#*:}/# ##}/ *} ) + _cache_virt_admin_cmds=( ${${${${(f):-"$(_call_program commands virt-admin help)"}:#*:}/# ##}/ *} ) local icmd for icmd in $interact_cmds; do _cache_virt_admin_cmds[$_cache_virt_admin_cmds[(i)$icmd]]=() done fi - if (( ! $+_cache_virt_admin_cmdopts )); then - typeset -gA _cache_virt_admin_cmdopts + if (( ! $+_cache_virt_admin_cmd_opts )); then + typeset -gA _cache_virt_admin_cmd_opts fi _arguments -A "-*" -C -S -s -w \ "$common_opts[@]" \ '1:command:->virt_admin_cmds' \ - '*:cmdopt:->virt_admin_cmdopts' && return + '*:cmdopt:->virt_admin_cmd_opts' && return # Same as with virsh above - [[ -z $state ]] && state=virt_admin_cmdopts + [[ -z $state ]] && state=virt_admin_cmd_opts ;; virt-host-validate) _arguments -A "-*" -S \ @@ -81,50 +113,113 @@ case $service in ;; esac +local -a conn_opt +if [[ -n ${(v)opt_args[(I)-c|--connect]} ]]; then + local uri=${(v)opt_args[(I)-c|--connect]} + [[ -z ${(Q)uri//([[:alnum:]]|+|:|\/|@|-|\.|\?|=)} ]] && \ + conn_opt=( -c $uri ) +fi + case $state in virsh_cmds) _wanted commands expl 'virsh command' compadd -a _cache_virsh_cmds && ret=0 ;; - virsh_cmdopts) - local cmd - if [[ $words[-1] == /* || $words[-1] == ./* ]]; then + virsh_cmd_opts) + if [[ $words[-2] == --(dir|emulatorbin|file|mountpoint|*path|script|source-dev) || $words[-1] == (/*|.*) ]]; then _default - return + return 0 fi + local cmd for (( i = 2; i <= $#words; i++ )); do [[ -n "${_cache_virsh_cmds[(r)$words[$i]]}" ]] && cmd=$words[$i] && break done [[ -z $cmd ]] && return 1 - if [[ -z $_cache_virsh_cmdopts[$cmd] ]]; then - _cache_virsh_cmdopts[$cmd]=${(M)${${${${=${(f)"$(_call_program virsh virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + local -a values + case $words[-2] in + --domain) + values=( $(_call_program domains "virsh ${(Q)conn_opt} list ${dom_opts[$cmd]:-"--all"} --name") ) + [[ -n $values ]] && _values domain ${=values} && return 0 + return 1 + ;; + --interface) + values=( ${${${${(f):-"$(_call_program interfaces "virsh ${(Q)conn_opt} iface-list ${iface_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) + [[ -n $values ]] && _values interface ${=values} && return 0 + return 1 + ;; + --network) + values=( $(_call_program networks "virsh ${(Q)conn_opt} net-list ${net_opts[$cmd]:-"--all"} --name") ) + [[ -n $values ]] && _values network ${=values} && return 0 + return 1 + ;; + --device) + values; values=( $(_call_program nodedevs "virsh ${(Q)conn_opt} nodedev-list") ) + [[ -n $values ]] && _values device ${=values} && return 0 + return 1 + ;; + --nwfilter) + values=( ${${${${(f):-"$(_call_program nwfilters "virsh ${(Q)conn_opt} nwfilter-list")"}/ UUID*/}:#---*}/ */} ) + [[ -n $values ]] && _values nwfilter ${=values} && return 0 + return 1 + ;; + --pool) + values=( ${${${${(f):-"$(_call_program pools "virsh ${(Q)conn_opt} pool-list ${pool_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) + [[ -n $values ]] && _values pool ${=values} && return 0 + return 1 + ;; + --secret) + values=( ${${${${(f):-"$(_call_program secrets "virsh ${(Q)conn_opt} secret-list")"}/ UUID*/}:#---*}/ */} ) + [[ -n $values ]] && _values secret ${=values} && return 0 + return 1 + ;; + --snapshotname) + local dom ; [[ ${(k)words[(I)--domain]} -gt 0 ]] && dom=${words[1+${(k)words[(I)--domain]}]} + [[ -z $dom ]] && return 1 + values=( ${${${${(f):-"$(_call_program snapshots "virsh ${(Q)conn_opt} snapshot-list --domain $dom 2>/dev/null")"}/ Name*/}:#---*}/ */} ) + [[ -n $values ]] && _values snapshot ${=values} && return 0 + return 1 + ;; + --vol) + local pool ; [[ ${(k)words[(I)--pool]} -gt 0 ]] && pool=${words[1+${(k)words[(I)--pool]}]} + [[ -z $pool ]] && return 1 + values=( ${${${${(f):-"$(_call_program volumes "virsh ${(Q)conn_opt} vol-list --pool $pool 2>/dev/null")"}/ Name*/}:#---*}/ */} ) + [[ -n $values ]] && _values volume ${=values} && return 0 + return 1 + ;; + esac + if [[ $cmd == help ]]; then + [[ $words[-1] == -* ]] && _values -w -- --command && return 0 + if [[ $words[-2] == help || $words[-2] == --command ]]; then + _values commands ${=_cache_virsh_cmds} && return 0 + fi + return 1 fi - _values -w options ${=_cache_virsh_cmdopts[$cmd]} && ret=0 + [[ -z $_cache_virsh_cmd_opts[$cmd] ]] && \ + _cache_virsh_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virsh virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + [[ -n ${=_cache_virsh_cmd_opts[$cmd]} ]] && \ + _values -w options ${=_cache_virsh_cmd_opts[$cmd]} && ret=0 ;; virt_admin_cmds) _wanted commands expl 'virt-admin command' compadd -a _cache_virt_admin_cmds && ret=0 ;; - virt_admin_cmdopts) + virt_admin_cmd_opts) local cmd for (( i = 2; i <= $#words; i++ )); do [[ -n "${_cache_virt_admin_cmds[(r)$words[$i]]}" ]] && cmd=$words[$i] && break done [[ -z $cmd ]] && return 1 if [[ $words[-2] == --server ]]; then - _values servers ${=${(S)${${(f)$(sudo virt-admin srv-list)}##*--- }//[0-9]* }} && return 0 + _values servers ${=${(S)${${(f)$(sudo virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 fi if [[ $words[-2] == --client ]]; then - local srv - for (( i = 2; i <= $#words; i++ )); do - [[ $words[$i] == --server ]] && srv=$words[$i+1] && break - done + local srv ; [[ ${(k)words[(I)--server]} -gt 0 ]] && srv=${words[1+${(k)words[(I)--server]}]} [[ -z $srv ]] && return 1 - _values servers ${=${${(f):-"$(sudo virt-admin srv-clients-list --server $srv)"}/ [a-z]*}//[^0-9]} && return 0 - fi - if [[ -z $_cache_virt_admin_cmdopts[$cmd] ]]; then - _cache_virt_admin_cmdopts[$cmd]=${(M)${${${${=${(f)"$(_call_program virt-admin virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + [[ -n ${srv//[[:alnum:]]} ]] && return 1 + _values servers ${=${${(f):-"$(sudo virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 fi - [[ -n $_cache_virt_admin_cmdopts[$cmd] ]] && \ - _values -w options ${=_cache_virt_admin_cmdopts[$cmd]} && ret=0 + [[ -z $_cache_virt_admin_cmd_opts[$cmd] ]] && \ + _cache_virt_admin_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virt-admin virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + [[ -n $_cache_virt_admin_cmd_opts[$cmd] ]] && \ + _values -w options ${=_cache_virt_admin_cmd_opts[$cmd]} && ret=0 ;; esac -- cgit v1.2.3 From 5b4cbcc842c6272c76e4bc0190006c589b5481cc Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Sat, 3 Sep 2016 12:41:22 +0200 Subject: 39158: cleanup following review comments of _libvirt function --- ChangeLog | 3 ++ Completion/Unix/Command/_libvirt | 60 +++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 29 deletions(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index 93051dd11..1241789de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-09-03 Oliver Kiddle + * Marko Myllynen: 39158: Completion/Unix/Command/_libvirt: + cleanup following review comments of function + * 39165: Completion/Unix/Command/_dmidecode, Completion/Unix/Command/_ant, Completion/Linux/Command/_ss, Completion/Unix/Command/_espeak, Completion/Unix/Command/_git, diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index 4fb963011..ad4c3b8e6 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -28,7 +28,7 @@ dom_opts=( screenshot " " send-key " " shutdown --state-running - start --state-shutoff + start --inactive suspend --state-running ttyconsole " " undefine --inactive @@ -116,6 +116,8 @@ esac local -a conn_opt if [[ -n ${(v)opt_args[(I)-c|--connect]} ]]; then local uri=${(v)opt_args[(I)-c|--connect]} + # For the libvirt remote URI syntax, see: + # https://libvirt.org/guide/html/Application_Development_Guide-Architecture-Remote_URIs.html [[ -z ${(Q)uri//([[:alnum:]]|+|:|\/|@|-|\.|\?|=)} ]] && \ conn_opt=( -c $uri ) fi @@ -135,68 +137,68 @@ case $state in done [[ -z $cmd ]] && return 1 local -a values - case $words[-2] in + case $words[CURRENT-1] in --domain) - values=( $(_call_program domains "virsh ${(Q)conn_opt} list ${dom_opts[$cmd]:-"--all"} --name") ) - [[ -n $values ]] && _values domain ${=values} && return 0 + values=( $(_call_program domains "virsh $conn_opt list ${dom_opts[$cmd]:-"--all"} --name") ) + [[ -n $values ]] && _wanted domains expl domain compadd ${=values} && return 0 return 1 ;; --interface) - values=( ${${${${(f):-"$(_call_program interfaces "virsh ${(Q)conn_opt} iface-list ${iface_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) - [[ -n $values ]] && _values interface ${=values} && return 0 + values=( ${${${${(f):-"$(_call_program interfaces "virsh $conn_opt iface-list ${iface_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) + [[ -n $values ]] && _wanted interfaces expl interface compadd ${=values} && return 0 return 1 ;; --network) - values=( $(_call_program networks "virsh ${(Q)conn_opt} net-list ${net_opts[$cmd]:-"--all"} --name") ) - [[ -n $values ]] && _values network ${=values} && return 0 + values=( $(_call_program networks "virsh $conn_opt net-list ${net_opts[$cmd]:-"--all"} --name") ) + [[ -n $values ]] && _wanted networks expl network compadd ${=values} && return 0 return 1 ;; --device) - values; values=( $(_call_program nodedevs "virsh ${(Q)conn_opt} nodedev-list") ) - [[ -n $values ]] && _values device ${=values} && return 0 + values; values=( $(_call_program nodedevs "virsh $conn_opt nodedev-list") ) + [[ -n $values ]] && _wanted devices expl device compadd ${=values} && return 0 return 1 ;; --nwfilter) - values=( ${${${${(f):-"$(_call_program nwfilters "virsh ${(Q)conn_opt} nwfilter-list")"}/ UUID*/}:#---*}/ */} ) - [[ -n $values ]] && _values nwfilter ${=values} && return 0 + values=( ${${${${(f):-"$(_call_program nwfilters "virsh $conn_opt nwfilter-list")"}/ UUID*/}:#---*}/ */} ) + [[ -n $values ]] && _wanted nwfilters expl nwfilter compadd ${=values} && return 0 return 1 ;; --pool) - values=( ${${${${(f):-"$(_call_program pools "virsh ${(Q)conn_opt} pool-list ${pool_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) - [[ -n $values ]] && _values pool ${=values} && return 0 + values=( ${${${${(f):-"$(_call_program pools "virsh $conn_opt pool-list ${pool_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) + [[ -n $values ]] && _wanted pools expl pool compadd ${=values} && return 0 return 1 ;; --secret) - values=( ${${${${(f):-"$(_call_program secrets "virsh ${(Q)conn_opt} secret-list")"}/ UUID*/}:#---*}/ */} ) - [[ -n $values ]] && _values secret ${=values} && return 0 + values=( ${${${${(f):-"$(_call_program secrets "virsh $conn_opt secret-list")"}/ UUID*/}:#---*}/ */} ) + [[ -n $values ]] && _wanted secrets expl secret compadd ${=values} && return 0 return 1 ;; --snapshotname) - local dom ; [[ ${(k)words[(I)--domain]} -gt 0 ]] && dom=${words[1+${(k)words[(I)--domain]}]} + local dom ; (( ${(k)words[(I)--domain]} > 0 )) && dom=${words[1+${(k)words[(I)--domain]}]} [[ -z $dom ]] && return 1 - values=( ${${${${(f):-"$(_call_program snapshots "virsh ${(Q)conn_opt} snapshot-list --domain $dom 2>/dev/null")"}/ Name*/}:#---*}/ */} ) - [[ -n $values ]] && _values snapshot ${=values} && return 0 + values=( ${${${${(f):-"$(_call_program snapshots "virsh $conn_opt snapshot-list --domain ${(q)dom} 2>/dev/null")"}/ Name*/}:#---*}/ */} ) + [[ -n $values ]] && _wanted snapshots expl snapshot compadd ${=values} && return 0 return 1 ;; --vol) - local pool ; [[ ${(k)words[(I)--pool]} -gt 0 ]] && pool=${words[1+${(k)words[(I)--pool]}]} + local pool ; (( ${(k)words[(I)--pool]} > 0 )) && pool=${words[1+${(k)words[(I)--pool]}]} [[ -z $pool ]] && return 1 - values=( ${${${${(f):-"$(_call_program volumes "virsh ${(Q)conn_opt} vol-list --pool $pool 2>/dev/null")"}/ Name*/}:#---*}/ */} ) - [[ -n $values ]] && _values volume ${=values} && return 0 + values=( ${${${${(f):-"$(_call_program volumes "virsh $conn_opt vol-list --pool ${(q)pool} 2>/dev/null")"}/ Name*/}:#---*}/ */} ) + [[ -n $values ]] && _wanted volumes expl volume compadd ${=values} && return 0 return 1 ;; esac if [[ $cmd == help ]]; then - [[ $words[-1] == -* ]] && _values -w -- --command && return 0 + [[ $words[-1] == -* ]] && _values -w option --command && return 0 if [[ $words[-2] == help || $words[-2] == --command ]]; then - _values commands ${=_cache_virsh_cmds} && return 0 + _wanted commands expl command compadd ${=_cache_virsh_cmds} && return 0 fi return 1 fi [[ -z $_cache_virsh_cmd_opts[$cmd] ]] && \ _cache_virsh_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virsh virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} [[ -n ${=_cache_virsh_cmd_opts[$cmd]} ]] && \ - _values -w options ${=_cache_virsh_cmd_opts[$cmd]} && ret=0 + _values -w option ${(u)=_cache_virsh_cmd_opts[$cmd]} && ret=0 ;; virt_admin_cmds) _wanted commands expl 'virt-admin command' compadd -a _cache_virt_admin_cmds && ret=0 @@ -208,18 +210,18 @@ case $state in done [[ -z $cmd ]] && return 1 if [[ $words[-2] == --server ]]; then - _values servers ${=${(S)${${(f)$(sudo virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 + _wanted servers expl server compadd ${=${(S)${${(f)$(sudo virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 fi if [[ $words[-2] == --client ]]; then - local srv ; [[ ${(k)words[(I)--server]} -gt 0 ]] && srv=${words[1+${(k)words[(I)--server]}]} + local srv ; (( ${(k)words[(I)--server]} > 0 )) && srv=${words[1+${(k)words[(I)--server]}]} [[ -z $srv ]] && return 1 [[ -n ${srv//[[:alnum:]]} ]] && return 1 - _values servers ${=${${(f):-"$(sudo virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 + _wanted clients expl client compadd ${=${${(f):-"$(sudo virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 fi [[ -z $_cache_virt_admin_cmd_opts[$cmd] ]] && \ _cache_virt_admin_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virt-admin virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} [[ -n $_cache_virt_admin_cmd_opts[$cmd] ]] && \ - _values -w options ${=_cache_virt_admin_cmd_opts[$cmd]} && ret=0 + _values -w option ${(u)=_cache_virt_admin_cmd_opts[$cmd]} && ret=0 ;; esac -- cgit v1.2.3 From 33a8a6f86cd63a1daf845b269f6c56ea477c891e Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Mon, 5 Sep 2016 10:39:16 +0300 Subject: 39179 (plus tweak): More _libvirt (virsh) completion tweaks --- ChangeLog | 5 +++++ Completion/Unix/Command/_libvirt | 21 ++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index f5d18990a..341555f9d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-06 Marko Myllynen + + * 39179 (plus tweak): Completion/Unix/Command/_libvirt: More + _libvirt (virsh) completion tweaks + 2016-09-05 Peter Stephenson * Teubel György: 39167: Src/init.c, Doc/Zsh/params.yo: Make $ENV diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index ad4c3b8e6..f93778876 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -127,13 +127,13 @@ case $state in _wanted commands expl 'virsh command' compadd -a _cache_virsh_cmds && ret=0 ;; virsh_cmd_opts) - if [[ $words[-2] == --(dir|emulatorbin|file|mountpoint|*path|script|source-dev) || $words[-1] == (/*|.*) ]]; then + if [[ $words[CURRENT-1] == --(dir|emulatorbin|file|mountpoint|*path|script|source-dev) || $words[CURRENT] == (/*|.*) ]]; then _default return 0 fi local cmd - for (( i = 2; i <= $#words; i++ )); do - [[ -n "${_cache_virsh_cmds[(r)$words[$i]]}" ]] && cmd=$words[$i] && break + for word in ${words:1}; do + [[ -n "${_cache_virsh_cmds[(r)$word]}" ]] && cmd=$word && break done [[ -z $cmd ]] && return 1 local -a values @@ -195,6 +195,13 @@ case $state in fi return 1 fi + # Allow passing domain without --domain with few of the most used commands + if [[ $cmd == (destroy|reboot|reset|start|shutdown) ]]; then + if [[ $words[CURRENT-1] == $cmd ]]; then + values=( $(_call_program domains "virsh $conn_opt list ${dom_opts[$cmd]:-"--all"} --name") ) + [[ -n $values ]] && _wanted domains expl domain compadd ${=values} && return 0 + fi + fi [[ -z $_cache_virsh_cmd_opts[$cmd] ]] && \ _cache_virsh_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virsh virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} [[ -n ${=_cache_virsh_cmd_opts[$cmd]} ]] && \ @@ -205,14 +212,14 @@ case $state in ;; virt_admin_cmd_opts) local cmd - for (( i = 2; i <= $#words; i++ )); do - [[ -n "${_cache_virt_admin_cmds[(r)$words[$i]]}" ]] && cmd=$words[$i] && break + for word in ${words:1}; do + [[ -n "${_cache_virt_admin_cmds[(r)$word]}" ]] && cmd=$word && break done [[ -z $cmd ]] && return 1 - if [[ $words[-2] == --server ]]; then + if [[ $words[CURRENT-1] == --server ]]; then _wanted servers expl server compadd ${=${(S)${${(f)$(sudo virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 fi - if [[ $words[-2] == --client ]]; then + if [[ $words[CURRENT-1] == --client ]]; then local srv ; (( ${(k)words[(I)--server]} > 0 )) && srv=${words[1+${(k)words[(I)--server]}]} [[ -z $srv ]] && return 1 [[ -n ${srv//[[:alnum:]]} ]] && return 1 -- cgit v1.2.3 From 3768fcc28a28b02ae786faa013fc132cad8582fa Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Tue, 6 Sep 2016 09:10:56 +0000 Subject: unposted: Fix leakage of $word (after 39179). --- ChangeLog | 5 +++++ Completion/Unix/Command/_libvirt | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index 618a45e43..327781d6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-06 Marko Myllynen + + * unposted: Completion/Unix/Command/_libvirt: Fix leakage of + $word (after 39179). + 2016-09-06 Peter Stephenson * 39181: Src/builtin.c, Src/zsh.h, Src/Zle/complete.c: Add diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index f93778876..d68f82d5e 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -131,7 +131,7 @@ case $state in _default return 0 fi - local cmd + local cmd word for word in ${words:1}; do [[ -n "${_cache_virsh_cmds[(r)$word]}" ]] && cmd=$word && break done @@ -211,7 +211,7 @@ case $state in _wanted commands expl 'virt-admin command' compadd -a _cache_virt_admin_cmds && ret=0 ;; virt_admin_cmd_opts) - local cmd + local cmd word for word in ${words:1}; do [[ -n "${_cache_virt_admin_cmds[(r)$word]}" ]] && cmd=$word && break done -- cgit v1.2.3 From 9a722df3a6643696a54421994c8908459e29a947 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 6 Sep 2016 01:59:22 +0000 Subject: unposted: _libvirt: Escape $words elements to avoid their interpretation as a pattern against $_cache_virsh_cmds. --- ChangeLog | 6 ++++++ Completion/Unix/Command/_libvirt | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index 327781d6b..d10ba8a26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2016-09-06 Daniel Shahaf + + * unposted: Completion/Unix/Command/_libvirt: Escape $words + elements to avoid their interpretation as a pattern against + $_cache_virsh_cmds. + 2016-09-06 Marko Myllynen * unposted: Completion/Unix/Command/_libvirt: Fix leakage of diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index d68f82d5e..8ddc28102 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -133,7 +133,7 @@ case $state in fi local cmd word for word in ${words:1}; do - [[ -n "${_cache_virsh_cmds[(r)$word]}" ]] && cmd=$word && break + [[ -n "${_cache_virsh_cmds[(r)${(b)word}]}" ]] && cmd=$word && break done [[ -z $cmd ]] && return 1 local -a values @@ -213,7 +213,7 @@ case $state in virt_admin_cmd_opts) local cmd word for word in ${words:1}; do - [[ -n "${_cache_virt_admin_cmds[(r)$word]}" ]] && cmd=$word && break + [[ -n "${_cache_virt_admin_cmds[(r)${(b)word}]}" ]] && cmd=$word && break done [[ -z $cmd ]] && return 1 if [[ $words[CURRENT-1] == --server ]]; then -- cgit v1.2.3 From 831a336c494b55641b4ba2c8bb89a8acda2709f8 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 6 Sep 2016 23:40:55 +0000 Subject: 39171: _libvirt: Apply $opt_args-unescaping. This causes the value of $conn_opt in the code not to have a backslash in front of the colon. --- ChangeLog | 3 +++ Completion/Unix/Command/_libvirt | 1 + 2 files changed, 4 insertions(+) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index d10ba8a26..be821de99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-09-06 Daniel Shahaf + * 39171: Completion/Unix/Command/_libvirt: Apply + $opt_args-unescaping. + * unposted: Completion/Unix/Command/_libvirt: Escape $words elements to avoid their interpretation as a pattern against $_cache_virsh_cmds. diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index 8ddc28102..658e197dc 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -116,6 +116,7 @@ esac local -a conn_opt if [[ -n ${(v)opt_args[(I)-c|--connect]} ]]; then local uri=${(v)opt_args[(I)-c|--connect]} + uri=${uri//(#m)\\([\\:])/${MATCH[2]}} # opt_args elements are colon-escaped # For the libvirt remote URI syntax, see: # https://libvirt.org/guide/html/Application_Development_Guide-Architecture-Remote_URIs.html [[ -z ${(Q)uri//([[:alnum:]]|+|:|\/|@|-|\.|\?|=)} ]] && \ -- cgit v1.2.3 From 8011fe8a582bd3c018a98e0e2c08f65233bcf0fc Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Sun, 11 Sep 2016 13:22:35 +0200 Subject: 39261 (tweaked cf. Daniel: 39275): don't unconditionally elevate privileges with sudo in completion functions A new gain-privileges style enables it and a _comp_priv_prefix array added for tracking how to match privileges for the current command --- ChangeLog | 15 +++++++++ Completion/BSD/Command/_jexec | 1 + Completion/Base/Core/_main_complete | 1 + Completion/Base/Utility/_call_program | 11 +++++-- Completion/Debian/Command/_dchroot | 1 + Completion/Debian/Command/_dchroot-dsa | 1 + Completion/Debian/Command/_schroot | 1 + Completion/Mandriva/Command/_rebootin | 2 +- Completion/Solaris/Command/_pfexec | 2 +- Completion/Solaris/Command/_zlogin | 2 ++ Completion/Unix/Command/_dsh | 1 + Completion/Unix/Command/_fsh | 1 + Completion/Unix/Command/_libvirt | 10 +++--- Completion/Unix/Command/_mosh | 1 + Completion/Unix/Command/_rlogin | 1 + Completion/Unix/Command/_ssh | 1 + Completion/Unix/Command/_sudo | 2 +- Doc/Zsh/compsys.yo | 59 +++++++++++++++++++++++++++++----- 18 files changed, 95 insertions(+), 18 deletions(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index 7fba3550c..78931adbb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2016-09-11 Oliver Kiddle + + * 39261 (tweaked cf. Daniel: 39275): Doc/Zsh/compsys.yo: + Completion/Base/Core/_main_complete, + Completion/Base/Utility/_call_program, + Completion/Debian/Command/_dchroot, + Completion/Debian/Command/_dchroot-dsa, + Completion/Debian/Command/_schroot, + Completion/Solaris/Command/_pfexec, + Completion/Solaris/Command/_zlogin, Completion/Unix/Command/_dsh, + Completion/Unix/Command/_fsh, Completion/Unix/Command/_libvirt, + Completion/Unix/Command/_mosh, Completion/Unix/Command/_rlogin, + Completion/Unix/Command/_ssh, Completion/Unix/Command/_sudo: + don't unconditionally gain privileges with sudo for completion + 2016-09-11 Daniel Shahaf * 39252: Src/Zle/compcore.c, Src/Zle/compctl.c, diff --git a/Completion/BSD/Command/_jexec b/Completion/BSD/Command/_jexec index 279812bbc..85829d10e 100644 --- a/Completion/BSD/Command/_jexec +++ b/Completion/BSD/Command/_jexec @@ -2,6 +2,7 @@ _jexec_normal() { local PATH=$PATH + local -a _comp_priv_prefix # relative paths are relative to the jail's root path=( "$(command jls -j $words[1] path)"/$^path ) shift 1 words; (( CURRENT-- )) diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete index 9c4cfac85..c292ce7d7 100644 --- a/Completion/Base/Core/_main_complete +++ b/Completion/Base/Core/_main_complete @@ -38,6 +38,7 @@ local func funcs ret=1 tmp _compskip format nm call match min max i num\ _saved_colors="$ZLS_COLORS" \ _saved_colors_set=${+ZLS_COLORS} \ _ambiguous_color='' +local -a _comp_priv_prefix # _precommand sets this to indicate we are following a precommand modifier local -a precommands diff --git a/Completion/Base/Utility/_call_program b/Completion/Base/Utility/_call_program index 010e09476..95c761e65 100644 --- a/Completion/Base/Utility/_call_program +++ b/Completion/Base/Utility/_call_program @@ -1,6 +1,13 @@ #autoload +X local tmp err_fd=-1 +local -a prefix + +if [[ "$1" = -p ]]; then + shift + zstyle -t ":completion:${curcontext}:${1}" gain-privileges && + prefix=( $_comp_priv_prefix ) +fi if (( ${debug_fd:--1} > 2 )) || [[ ! -t 2 ]] then exec {err_fd}>&2 # debug_fd is saved stderr, 2 is trace or redirect @@ -13,10 +20,10 @@ if zstyle -s ":completion:${curcontext}:${1}" command tmp; then if [[ "$tmp" = -* ]]; then eval "$tmp[2,-1]" "$argv[2,-1]" else - eval "$tmp" + eval $prefix "$tmp" fi else - eval "$argv[2,-1]" + eval $prefix "$argv[2,-1]" fi 2>&$err_fd } always { diff --git a/Completion/Debian/Command/_dchroot b/Completion/Debian/Command/_dchroot index c26e5691a..2a6f5d808 100644 --- a/Completion/Debian/Command/_dchroot +++ b/Completion/Debian/Command/_dchroot @@ -2,6 +2,7 @@ local expl context state line typeset -A opt_args +local -a _comp_priv_prefix _arguments -S \ '(-h --help)'{-h,--help}'[help]' \ diff --git a/Completion/Debian/Command/_dchroot-dsa b/Completion/Debian/Command/_dchroot-dsa index d4668b553..e8e981b84 100644 --- a/Completion/Debian/Command/_dchroot-dsa +++ b/Completion/Debian/Command/_dchroot-dsa @@ -2,6 +2,7 @@ local expl context state line typeset -A opt_args +local -a _comp_priv_prefix _arguments -S \ '(-h --help)'{-h,--help}'[help]' \ diff --git a/Completion/Debian/Command/_schroot b/Completion/Debian/Command/_schroot index 06117be88..117df45ef 100644 --- a/Completion/Debian/Command/_schroot +++ b/Completion/Debian/Command/_schroot @@ -2,6 +2,7 @@ local expl context state line typeset -A opt_args +local -a _comp_priv_prefix _arguments -S \ '(-h --help)'{-h,--help}'[help]' \ diff --git a/Completion/Mandriva/Command/_rebootin b/Completion/Mandriva/Command/_rebootin index 3f30b2591..284ff08f1 100644 --- a/Completion/Mandriva/Command/_rebootin +++ b/Completion/Mandriva/Command/_rebootin @@ -2,7 +2,7 @@ local context state line expl typeset -A opt_args -local loader=$(sudo detectloader -q) +local loader=${$(_call_program -p entries detectloader -q):-GRUB} _arguments -s \ '-n[no immediate reboot just set the flags for next reboot]' \ diff --git a/Completion/Solaris/Command/_pfexec b/Completion/Solaris/Command/_pfexec index 227336223..3f1f3e733 100644 --- a/Completion/Solaris/Command/_pfexec +++ b/Completion/Solaris/Command/_pfexec @@ -25,7 +25,7 @@ _pfexec() { _arguments \ '-P[privileges to acquire]:privspec:_privset' \ '(-):command name: _command_names -e' \ - '*::arguments: _normal' + '*::arguments:{ _comp_priv_prefix=( $words[1] ${(kv)opt_args[-P]} ) ; _normal }' } _pfexec "$@" diff --git a/Completion/Solaris/Command/_zlogin b/Completion/Solaris/Command/_zlogin index 04018eb87..065f55b03 100644 --- a/Completion/Solaris/Command/_zlogin +++ b/Completion/Solaris/Command/_zlogin @@ -1,6 +1,8 @@ #compdef zlogin # Synced with the Nevada build 162 man page +local -a _comp_priv_prefix + _zlogin() { _arguments -s \ '-E[Disable escape character]' \ diff --git a/Completion/Unix/Command/_dsh b/Completion/Unix/Command/_dsh index 688e024ce..8c5c23208 100644 --- a/Completion/Unix/Command/_dsh +++ b/Completion/Unix/Command/_dsh @@ -2,6 +2,7 @@ local curcontext="$curcontext" state line expl typeset -A opt_args +local -a _comp_priv_prefix _arguments -s -C -S \ '(-v --verbose -q --quiet)'{-v,--verbose}'[verbose output]' \ diff --git a/Completion/Unix/Command/_fsh b/Completion/Unix/Command/_fsh index d9ced5feb..c39373117 100644 --- a/Completion/Unix/Command/_fsh +++ b/Completion/Unix/Command/_fsh @@ -1,6 +1,7 @@ #compdef fsh local curcontext="$curcontext" state line ret=1 +local -a _comp_priv_prefix _arguments -C \ '(- : *)'{-h,--help}'[display help information]' \ diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index 658e197dc..17b02be81 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -155,7 +155,7 @@ case $state in return 1 ;; --device) - values; values=( $(_call_program nodedevs "virsh $conn_opt nodedev-list") ) + values; values=( $(_call_program devices "virsh $conn_opt nodedev-list") ) [[ -n $values ]] && _wanted devices expl device compadd ${=values} && return 0 return 1 ;; @@ -204,7 +204,7 @@ case $state in fi fi [[ -z $_cache_virsh_cmd_opts[$cmd] ]] && \ - _cache_virsh_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virsh virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + _cache_virsh_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program options virsh help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} [[ -n ${=_cache_virsh_cmd_opts[$cmd]} ]] && \ _values -w option ${(u)=_cache_virsh_cmd_opts[$cmd]} && ret=0 ;; @@ -218,16 +218,16 @@ case $state in done [[ -z $cmd ]] && return 1 if [[ $words[CURRENT-1] == --server ]]; then - _wanted servers expl server compadd ${=${(S)${${(f)$(sudo virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 + _wanted servers expl server compadd ${=${(S)${${(f)$(_call_program -p servers virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 fi if [[ $words[CURRENT-1] == --client ]]; then local srv ; (( ${(k)words[(I)--server]} > 0 )) && srv=${words[1+${(k)words[(I)--server]}]} [[ -z $srv ]] && return 1 [[ -n ${srv//[[:alnum:]]} ]] && return 1 - _wanted clients expl client compadd ${=${${(f):-"$(sudo virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 + _wanted clients expl client compadd ${=${${(f):-"$(_call_program -p clients virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 fi [[ -z $_cache_virt_admin_cmd_opts[$cmd] ]] && \ - _cache_virt_admin_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program virt-admin virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} + _cache_virt_admin_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program options virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} [[ -n $_cache_virt_admin_cmd_opts[$cmd] ]] && \ _values -w option ${(u)=_cache_virt_admin_cmd_opts[$cmd]} && ret=0 ;; diff --git a/Completion/Unix/Command/_mosh b/Completion/Unix/Command/_mosh index c19f6ebde..431fdbf9e 100644 --- a/Completion/Unix/Command/_mosh +++ b/Completion/Unix/Command/_mosh @@ -1,6 +1,7 @@ #compdef mosh local curcontext="$curcontext" state line +local -a _comp_priv_prefix _arguments -C \ '(-)--help[display help information]' \ diff --git a/Completion/Unix/Command/_rlogin b/Completion/Unix/Command/_rlogin index a04c6d068..8f74939fd 100644 --- a/Completion/Unix/Command/_rlogin +++ b/Completion/Unix/Command/_rlogin @@ -12,6 +12,7 @@ _rlogin () { rsh|remsh) local context state line ret=1 typeset -A opt_args + local -a _comp_priv_prefix _arguments -s \ '-n[ignore stdin]' \ diff --git a/Completion/Unix/Command/_ssh b/Completion/Unix/Command/_ssh index 7b2cdd8e1..5ee4fd2ad 100644 --- a/Completion/Unix/Command/_ssh +++ b/Completion/Unix/Command/_ssh @@ -605,6 +605,7 @@ _ssh () { hmac-sha2-256-96 hmac-sha2-512 hmac-sha2-512-96 && ret=0 ;; command) + local -a _comp_priv_prefix shift 1 words (( CURRENT-- )) _normal diff --git a/Completion/Unix/Command/_sudo b/Completion/Unix/Command/_sudo index 63ac37f62..21b1ef4c6 100644 --- a/Completion/Unix/Command/_sudo +++ b/Completion/Unix/Command/_sudo @@ -48,7 +48,7 @@ else '(-H --set-home -i --login -s --shell -e --edit)'{-H,--set-home}"[set HOME variable to target user's home dir]" \ '(-P --preserve-groups -i -login -s --shell -e --edit)'{-P,--preserve-groups}"[preserve group vector instead of setting to target's]" \ '(-)1:command: _command_names -e' - '*::arguments: _normal' + '*::arguments:{ _comp_priv_prefix=( $words[1] -n ${(kv)opt_args[(I)(-[ugHEP]|--(user|group|set-home|preserve-env|preserve-groups))]} ) ; _normal }' ) fi diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index ecf17e728..bc036ada5 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -1842,6 +1842,15 @@ In the case of the tt(_match) completer, the style may also be set to the string `tt(pattern)'. Then the pattern on the line is left unchanged if it does not match unambiguously. ) +kindex(gain-privileges, completion style) +item(tt(gain-privileges))( +If set to tt(true), this style enables the use of commands like tt(sudo) +or tt(doas) to gain extra privileges when retrieving information for +completion. This is only done when a command such as tt(sudo) appears on +the command-line. To force the use of, e.g. tt(sudo) or to override any +prefix that might be added due to tt(gain-privileges), the tt(command) +style can be used with a value that begins with a hyphen. +) kindex(keep-prefix, completion style) item(tt(keep-prefix))( This style is used by the tt(_expand) completer. If it is `true', the @@ -3471,12 +3480,6 @@ generating matches all follow the convention of returning status zero if they generated completions and non-zero if no matching completions could be added. -Two more features are offered by the tt(_main_complete) function. The -arrays tt(compprefuncs) and tt(comppostfuncs) may contain -names of functions that are to be called immediately before or after -completion has been tried. A function will only be called once unless -it explicitly reinserts itself into the array. - startitem() findex(_absolute_command_paths) item(tt(_absolute_command_paths))( @@ -4173,7 +4176,7 @@ The return status of tt(_call_function) itself is zero if the function var(name) exists and was called and non-zero otherwise. ) findex(_call_program) -item(tt(_call_program) var(tag) var(string) ...)( +item(tt(_call_program) [ tt(-p) ] var(tag) var(string) ...)( This function provides a mechanism for the user to override the use of an external command. It looks up the tt(command) style with the supplied var(tag). If the style is set, its value is used as the command to @@ -4181,6 +4184,13 @@ execute. The var(string)s from the call to tt(_call_program), or from the style if set, are concatenated with spaces between them and the resulting string is evaluated. The return status is the return status of the command called. + +If the option `tt(-p)' is supplied it indicates that the command +output is influenced by the permissions it is run with. If the +tt(gain-privileges) style is set to true, tt(_call_program) will make +use of commands such as tt(sudo), if present on the command-line, to +match the permissions to whatever the final command is likely to run +under. ) findex(_combination) item(tt(_combination) [ tt(-s) var(pattern) ] var(tag) var(style) var(spec) ... var(field) var(opts) ...)( @@ -5073,7 +5083,40 @@ ifnzman(noderef(The zsh/zleparameter Module)). ) enditem() -texinode(Completion Directories)()(Completion Functions)(Completion System) +texinode(Completion System Variables)(Completion Directories)(Completion Functions)(Completion System) +sect(Completion System Variables) +cindex(completion system, variables) + +There are some standard variables, initialised by the tt(_main_complete) +function and then used from other functions. + +The standard variables are: + +startitem() +item(tt(_comp_caller_options))( +The completion system uses tt(setopt) to set a number of options. This +allows functions to be written without concern for compatibility with +every possible combination of user options. However, sometimes completion +needs to know what the user's option preferences are. These are saved +in the tt(_comp_caller_options) associative array. Option names, spelled +in lowercase without underscores, are mapped to one or other of the +strings `tt(on)' and `tt(off)'. +) + +item(tt(_comp_priv_prefix))( +Completion functions such as tt(_sudo) can set the tt(_comp_priv_prefix) +array to a command prefix that may then be used by tt(_call_program) to +match the privileges when calling programs to generate matches. +) +enditem() + +Two more features are offered by the tt(_main_complete) function. The +arrays tt(compprefuncs) and tt(comppostfuncs) may contain +names of functions that are to be called immediately before or after +completion has been tried. A function will only be called once unless +it explicitly reinserts itself into the array. + +texinode(Completion Directories)()(Completion System Variables)(Completion System) sect(Completion Directories) cindex(completion system, directory structure) -- cgit v1.2.3 From 420cde915804d790277e34295127cef3cd9b3894 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Wed, 14 Sep 2016 07:05:35 +0000 Subject: 39199: _libvirt: Support libvirt URLs that contain a literal question mark under noglob. E.g., % noglob virsh -c qemu:///system? start Conflicts with 39261 resolved. --- ChangeLog | 3 +++ Completion/Unix/Command/_libvirt | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index 6ce876e08..1b121be13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2016-09-14 Daniel Shahaf + * 39199: Completion/Unix/Command/_libvirt: Support libvirt URLs + that contain a literal question mark under noglob. + * unposted: Completion/Unix/Command/_git: Permit multiple -c options. diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index 17b02be81..716bca03c 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -140,51 +140,51 @@ case $state in local -a values case $words[CURRENT-1] in --domain) - values=( $(_call_program domains "virsh $conn_opt list ${dom_opts[$cmd]:-"--all"} --name") ) + values=( $(_call_program domains "noglob virsh $conn_opt list ${dom_opts[$cmd]:-"--all"} --name") ) [[ -n $values ]] && _wanted domains expl domain compadd ${=values} && return 0 return 1 ;; --interface) - values=( ${${${${(f):-"$(_call_program interfaces "virsh $conn_opt iface-list ${iface_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) + values=( ${${${${(f):-"$(_call_program interfaces "noglob virsh $conn_opt iface-list ${iface_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) [[ -n $values ]] && _wanted interfaces expl interface compadd ${=values} && return 0 return 1 ;; --network) - values=( $(_call_program networks "virsh $conn_opt net-list ${net_opts[$cmd]:-"--all"} --name") ) + values=( $(_call_program networks "noglob virsh $conn_opt net-list ${net_opts[$cmd]:-"--all"} --name") ) [[ -n $values ]] && _wanted networks expl network compadd ${=values} && return 0 return 1 ;; --device) - values; values=( $(_call_program devices "virsh $conn_opt nodedev-list") ) + values; values=( $(_call_program devices "noglob virsh $conn_opt nodedev-list") ) [[ -n $values ]] && _wanted devices expl device compadd ${=values} && return 0 return 1 ;; --nwfilter) - values=( ${${${${(f):-"$(_call_program nwfilters "virsh $conn_opt nwfilter-list")"}/ UUID*/}:#---*}/ */} ) + values=( ${${${${(f):-"$(_call_program nwfilters "noglob virsh $conn_opt nwfilter-list")"}/ UUID*/}:#---*}/ */} ) [[ -n $values ]] && _wanted nwfilters expl nwfilter compadd ${=values} && return 0 return 1 ;; --pool) - values=( ${${${${(f):-"$(_call_program pools "virsh $conn_opt pool-list ${pool_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) + values=( ${${${${(f):-"$(_call_program pools "noglob virsh $conn_opt pool-list ${pool_opts[$cmd]:-"--all"}")"}/ Name*/}:#---*}/ */} ) [[ -n $values ]] && _wanted pools expl pool compadd ${=values} && return 0 return 1 ;; --secret) - values=( ${${${${(f):-"$(_call_program secrets "virsh $conn_opt secret-list")"}/ UUID*/}:#---*}/ */} ) + values=( ${${${${(f):-"$(_call_program secrets "noglob virsh $conn_opt secret-list")"}/ UUID*/}:#---*}/ */} ) [[ -n $values ]] && _wanted secrets expl secret compadd ${=values} && return 0 return 1 ;; --snapshotname) local dom ; (( ${(k)words[(I)--domain]} > 0 )) && dom=${words[1+${(k)words[(I)--domain]}]} [[ -z $dom ]] && return 1 - values=( ${${${${(f):-"$(_call_program snapshots "virsh $conn_opt snapshot-list --domain ${(q)dom} 2>/dev/null")"}/ Name*/}:#---*}/ */} ) + values=( ${${${${(f):-"$(_call_program snapshots "noglob virsh $conn_opt snapshot-list --domain ${(q)dom} 2>/dev/null")"}/ Name*/}:#---*}/ */} ) [[ -n $values ]] && _wanted snapshots expl snapshot compadd ${=values} && return 0 return 1 ;; --vol) local pool ; (( ${(k)words[(I)--pool]} > 0 )) && pool=${words[1+${(k)words[(I)--pool]}]} [[ -z $pool ]] && return 1 - values=( ${${${${(f):-"$(_call_program volumes "virsh $conn_opt vol-list --pool ${(q)pool} 2>/dev/null")"}/ Name*/}:#---*}/ */} ) + values=( ${${${${(f):-"$(_call_program volumes "noglob virsh $conn_opt vol-list --pool ${(q)pool} 2>/dev/null")"}/ Name*/}:#---*}/ */} ) [[ -n $values ]] && _wanted volumes expl volume compadd ${=values} && return 0 return 1 ;; @@ -199,7 +199,7 @@ case $state in # Allow passing domain without --domain with few of the most used commands if [[ $cmd == (destroy|reboot|reset|start|shutdown) ]]; then if [[ $words[CURRENT-1] == $cmd ]]; then - values=( $(_call_program domains "virsh $conn_opt list ${dom_opts[$cmd]:-"--all"} --name") ) + values=( $(_call_program domains "noglob virsh $conn_opt list ${dom_opts[$cmd]:-"--all"} --name") ) [[ -n $values ]] && _wanted domains expl domain compadd ${=values} && return 0 fi fi @@ -224,7 +224,7 @@ case $state in local srv ; (( ${(k)words[(I)--server]} > 0 )) && srv=${words[1+${(k)words[(I)--server]}]} [[ -z $srv ]] && return 1 [[ -n ${srv//[[:alnum:]]} ]] && return 1 - _wanted clients expl client compadd ${=${${(f):-"$(_call_program -p clients virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 + _wanted clients expl client compadd ${=${${(f):-"$(_call_program -p clients noglob virt-admin ${(Q)conn_opt} srv-clients-list --server $srv 2>/dev/null)"}/ [a-z]*}//[^0-9]} && return 0 fi [[ -z $_cache_virt_admin_cmd_opts[$cmd] ]] && \ _cache_virt_admin_cmd_opts[$cmd]=${(M)${${${${=${(f)"$(_call_program options virt-admin help $cmd 2>&1)"}}/\[}/\]}/\;}:#-[-0-9A-Za-z]*} -- cgit v1.2.3 From be4c072cf50ffcc2e2c34e4edbb0e2a78900206b Mon Sep 17 00:00:00 2001 From: Marko Myllynen Date: Wed, 14 Sep 2016 10:21:19 +0300 Subject: unposted: _libvirt: Add another noglob. (Follow-up to 39199) --- ChangeLog | 5 +++++ Completion/Unix/Command/_libvirt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'Completion/Unix/Command/_libvirt') diff --git a/ChangeLog b/ChangeLog index 1b121be13..0c0b72272 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-09-14 Marko Myllynen + + * unposted: Completion/Unix/Command/_libvirt: Add another + noglob. (Follow-up to 39199) + 2016-09-14 Daniel Shahaf * 39199: Completion/Unix/Command/_libvirt: Support libvirt URLs diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index 716bca03c..1aa8ed817 100644 --- a/Completion/Unix/Command/_libvirt +++ b/Completion/Unix/Command/_libvirt @@ -218,7 +218,7 @@ case $state in done [[ -z $cmd ]] && return 1 if [[ $words[CURRENT-1] == --server ]]; then - _wanted servers expl server compadd ${=${(S)${${(f)$(_call_program -p servers virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 + _wanted servers expl server compadd ${=${(S)${${(f)$(_call_program -p servers noglob virt-admin ${(Q)conn_opt} srv-list)}##*--- }//[0-9]* }} && return 0 fi if [[ $words[CURRENT-1] == --client ]]; then local srv ; (( ${(k)words[(I)--server]} > 0 )) && srv=${words[1+${(k)words[(I)--server]}]} -- cgit v1.2.3