Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: device cannot be completed after "ip link show dev"



On Mon, Mar 30, 2015 at 09:52:20PM -0700, Bart Schaefer wrote:
> diff --git a/Completion/Unix/Command/_ip b/Completion/Unix/Command/_ip
> index 3b68c35..c0a28d3 100644
> --- a/Completion/Unix/Command/_ip
> +++ b/Completion/Unix/Command/_ip
> @@ -9,7 +9,8 @@
>  # Values encoding simple types
>  #
>  local -a subcmd_dev
> -subcmd_dev=(/$'[[:alnum:][:punct:][:cntrl:][:digit:]]##\0'/ ':interfaces:network interface:_net_interfaces')
> +subcmd_dev=(/$'[[:alnum:][:punct:][:cntrl:][:digit:]]##\0'/ ':interfaces:network interface:_net_interfaces' "|"
> +  /$'dev\0'/ ':interfaces:network interface:_net_interfaces')
>  
>  local -a subcmd_onoff
>  subcmd_onoff=(/$'(on|off)\0'/ ':onoff:state (on or off):(on off)')
> 
This works pretty good, besides "dev" will be completed after "dev".
> 
> I suspect there should be some way to use the "-GUARD" syntax to prevent
> "dev" from completing again after "dev" ("ip link show dev dev" doesn't
> make sense, does it?) but there's no example of using a guard, and as
> someone implied, offering too much (as long as it's not *TOO* much) is
> better than offering too little.

I found that we can use "-'false'" as the the guard here:

subcmd_dev=(/$'[[:alnum:][:punct:][:cntrl:][:digit:]]##\0'/ -'false'
':interfaces:network interface:_net_interfaces')

then only network device will be completed after dev:

% ip link show dev<tab>
network interface
em1     lo      tun0    wlp3s0

or even using "[]" as the pattern has the same effect:

subcmd_dev=(/$'[]'/ ':interfaces:network interface:_net_interfaces')

But both of them will report parsing error when trying to complete after
the interface:

% ip link show dev lo<tab>
parse failed before current word




Messages sorted by: Reverse Date, Date, Thread, Author