completions/ipset: Don't error on loading

`ipset list --name` is a privileged operation, and it prints an
"Operation not permitted" error when done as a normal user.

What's worse, this did it on loading (the command substitution wasn't
quoted), so we'd print the error as soon as you did `ipset `.

Only do the operation when necessary, and don't print the error.

This'll effectively only make it work for root shells (not e.g. `sudo
ipset`), but I don't want to sprinkle `sudo` in the completion.

(Also why does listing stuff require root? That's not how it works
e.g. for ips. But I don't actually know what ipset is for, so maybe
there is a good reason.)

[ci skip]
This commit is contained in:
Fabian Homborg 2019-03-03 12:39:36 +01:00
parent dac5d79059
commit 8939a7ba7a

View file

@ -13,7 +13,7 @@ function __fish_ipset_needs_setname
end end
function __fish_ipset_list_sets function __fish_ipset_list_sets
set -l ipset_list (ipset list --name) set -l ipset_list (ipset list --name 2>/dev/null)
if not __fish_seen_subcommand_from $ipset_list if not __fish_seen_subcommand_from $ipset_list
echo $ipset_list echo $ipset_list
end end
@ -27,7 +27,7 @@ complete -c ipset --no-files --condition __fish_ipset_nosubcommand -a 'x' -d 'De
complete -c ipset --no-files --condition __fish_ipset_nosubcommand -a 'destroy' -d 'Destroy the specified set or all sets' complete -c ipset --no-files --condition __fish_ipset_nosubcommand -a 'destroy' -d 'Destroy the specified set or all sets'
complete -c ipset --no-files --condition __fish_ipset_nosubcommand -a 'list' -d 'a' complete -c ipset --no-files --condition __fish_ipset_nosubcommand -a 'list' -d 'a'
complete -c ipset --no-files --condition __fish_ipset_needs_setname -a (__fish_ipset_list_sets) complete -c ipset --no-files --condition __fish_ipset_needs_setname -a '(__fish_ipset_list_sets)'
complete -c ipset --no-files -s '!' -o 'exist' -d 'Ignore errors' complete -c ipset --no-files -s '!' -o 'exist' -d 'Ignore errors'
complete -c ipset --no-files -s 'o' -o 'output' -a 'plain save xml' -d 'Output format to the list command' complete -c ipset --no-files -s 'o' -o 'output' -a 'plain save xml' -d 'Output format to the list command'