From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18174 invoked by alias); 5 Sep 2016 10:29:40 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39179 Received: (qmail 4745 invoked from network); 5 Sep 2016 10:29:40 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm0-f46.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.46):SA:0(-0.0/5.0):. Processed in 0.351996 secs); 05 Sep 2016 10:29:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: myllynen@redhat.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 74.125.82.46 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:reply-to:to:from:subject:organization:message-id :date:user-agent:mime-version:content-transfer-encoding; bh=GleI6HPWMpTG7mk5YYKDs/jTXn29iVDQsj9aIVBDtng=; b=hfGisQLcRuJyQesA/36XnDY3mrK/J/UQXZi0H/jrV1wLNQm1DF7FhdLlGHThiIQjBi KOzI593FJpA3v085UfAUNVyprkmaLI1qMHNSSz6VKCXpxHHoznNB6JAecGq+UNZYJkhy DwBwOrxxeXflTyb6/PmOwy4sEiZivjLUp29IabOQgiYDEbs0ekKNC6riihqWyQLLUCz9 YBagSZ7bXeJQK1CBLIpTj/SBTorAaS4AL6iaD5OjbJxPcUQyQYBrkO7Jb5Y9ZnaBWDF7 NSXlMmjSfO1y7JL6DY9HWnoFGWw8Va3fOGLkd3NmEfep5cBxDwmx6W8/i9hIDpxAp7+Y LoCQ== X-Gm-Message-State: AE9vXwOR9wJqNfhRLfQaAIyG0H09Xaf4dYG16MgvoyfusYPUlygtqGlPUvYgVKFot4GQCNXW X-Received: by 10.28.51.21 with SMTP id z21mr13316972wmz.24.1473061158830; Mon, 05 Sep 2016 00:39:18 -0700 (PDT) Reply-To: Marko Myllynen To: zsh workers From: Marko Myllynen Subject: More _libvirt (virsh) completion tweaks Organization: Red Hat Message-ID: <2a9d0f77-a2af-a6aa-93b6-962204258164@redhat.com> Date: Mon, 5 Sep 2016 10:39:16 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Hi, Below is a quick patch to update _libvirt/virsh completions based on suggestions from Daniel. Most notably, we now complete domains without the --domain option in case no other options are provided. I picked up few commands which I think are most often used, please feel free to adjust the list of commands if you have other commands in mind. --- Completion/Unix/Command/_libvirt | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Completion/Unix/Command/_libvirt b/Completion/Unix/Command/_libvirt index ad4c3b8..ee80f3f 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[-1] == (/*|.*) ]]; 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 Thanks, -- Marko Myllynen