* More _libvirt (virsh) completion tweaks
@ 2016-09-05 7:39 Marko Myllynen
2016-09-06 0:16 ` Daniel Shahaf
0 siblings, 1 reply; 3+ messages in thread
From: Marko Myllynen @ 2016-09-05 7:39 UTC (permalink / raw)
To: zsh workers
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: More _libvirt (virsh) completion tweaks
2016-09-05 7:39 More _libvirt (virsh) completion tweaks Marko Myllynen
@ 2016-09-06 0:16 ` Daniel Shahaf
2016-09-06 8:46 ` Marko Myllynen
0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2016-09-06 0:16 UTC (permalink / raw)
To: Marko Myllynen; +Cc: zsh workers
Marko Myllynen wrote on Mon, Sep 05, 2016 at 10:39:16 +0300:
> 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.
Sure, we can add them as we run across them.
> +++ b/Completion/Unix/Command/_libvirt
> @@ -127,13 +127,13 @@ case $state in
> - 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
The second disjunct should use $words[CURRENT] rather than $words[-1].
I've amended this and pushed.
Thanks for all the patches1
Daniel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: More _libvirt (virsh) completion tweaks
2016-09-06 0:16 ` Daniel Shahaf
@ 2016-09-06 8:46 ` Marko Myllynen
0 siblings, 0 replies; 3+ messages in thread
From: Marko Myllynen @ 2016-09-06 8:46 UTC (permalink / raw)
To: Daniel Shahaf; +Cc: zsh workers
Hi,
On 2016-09-06 03:16, Daniel Shahaf wrote:
> Marko Myllynen wrote on Mon, Sep 05, 2016 at 10:39:16 +0300:
>> 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.
>
> Sure, we can add them as we run across them.
>
>> +++ b/Completion/Unix/Command/_libvirt
>> @@ -127,13 +127,13 @@ case $state in
>> - 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
>
> The second disjunct should use $words[CURRENT] rather than $words[-1].
> I've amended this and pushed.
Yes, correct, thanks for all your help!
Cheers,
--
Marko Myllynen
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-09-06 8:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-05 7:39 More _libvirt (virsh) completion tweaks Marko Myllynen
2016-09-06 0:16 ` Daniel Shahaf
2016-09-06 8:46 ` Marko Myllynen
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).