summary refs log tree commit diff
path: root/Completion/Unix/Command
diff options
context:
space:
mode:
authorMarko Myllynen <myllynen@redhat.com>2016-09-05 10:39:16 +0300
committerDaniel Shahaf <d.s@daniel.shahaf.name>2016-09-06 00:13:42 +0000
commit33a8a6f86cd63a1daf845b269f6c56ea477c891e (patch)
tree42ceaf962e2ccce307805517c27235eac6cad21c /Completion/Unix/Command
parentfde365ea8ba91a4e7daa27dfd63fdadb55a882f5 (diff)
downloadzsh-33a8a6f86cd63a1daf845b269f6c56ea477c891e.tar.gz
zsh-33a8a6f86cd63a1daf845b269f6c56ea477c891e.tar.xz
zsh-33a8a6f86cd63a1daf845b269f6c56ea477c891e.zip
39179 (plus tweak): More _libvirt (virsh) completion tweaks
Diffstat (limited to 'Completion/Unix/Command')
-rw-r--r--Completion/Unix/Command/_libvirt21
1 files changed, 14 insertions, 7 deletions
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