From 2d2f7c8fb1ca283183148fb472e7424212ac964c Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 12 Nov 2018 16:28:24 +0100 Subject: [PATCH] completions/ip: Restyle Just run `fish_indent` on the entire thing. --- share/completions/ip.fish | 623 +++++++++++++++++++------------------- 1 file changed, 312 insertions(+), 311 deletions(-) diff --git a/share/completions/ip.fish b/share/completions/ip.fish index f1a77fcd3..05e3de3d4 100644 --- a/share/completions/ip.fish +++ b/share/completions/ip.fish @@ -10,310 +10,311 @@ set -l ip_link l li lin link set -l ip_all_commands $ip_commands $ip_addr $ip_link function __fish_ip_commandwords - set -l skip 0 - set -l cmd (commandline -opc) - # HACK: Handle and/or/not specially because they have hardcoded completion behavior - # that doesn't remove them from the commandline - if contains -- $cmd[1] and or not - set -e cmd[1] - end - # Remove the first word because it's "ip" or an alias for it - set -e cmd[1] - set -l have_command 0 - for word in $cmd - switch $word - # Normalize the commands to their full form - `ip a` is `ip address` - # This can't be just an unambiguity check because there's also `ip addrlabel` - case a ad add addr addre addres address - # "addr add" is a thing, so we can only echo "address" if it's actually the command - if test $have_command = 0 - set have_command 1 - echo address - else - echo $word - end - case l li lin link - if test $have_command = 0 - set have_command 1 - echo link - else - echo $word - end - case "addrl*" - if test $have_command = 0 - set have_command 1 - echo addrlabel - else - echo $word - end - case r ro rou rout route - if test $have_command = 0 - set have_command 1 - echo route - else - echo $word - end - case "ru*" - if test $have_command = 0 - set have_command 1 - echo rule - else - echo $word - end - case n ne nei neig neigh - if test $have_command = 0 - set have_command 1 - echo neigh - else - echo $word - end - case nt - if test $have_command = 0 - set have_command 1 - echo ntable - else - echo $word - end - case t tu tun tunn tunne tunnel - if test $have_command = 0 - set have_command 1 - echo tunnel - else - echo $word - end - case "tunt*" - if test $have_command = 0 - set have_command 1 - echo tuntap - else - echo $word - end - case m ma mad madd maddr maddre maddres maddress - if test $have_command = 0 - set have_command 1 - echo maddress - else - echo $word - end - case mr "mro*" - if test $have_command = 0 - set have_command 1 - echo mroute - else - echo $word - end - case "mru*" - if test $have_command = 0 - set have_command 1 - echo mrule - else - echo $word - end - case "mo*" - if test $have_command = 0 - set have_command 1 - echo monitor - else - echo $word - end - case "x*" - if test $have_command = 0 - set have_command 1 - echo xfrm - else - echo $word - end - case "net*" - if test $have_command = 0 - set have_command 1 - echo netns - else - echo $word - end - case "l*" - if test $have_command = 0 - set have_command 1 - echo l2tp - else - echo $word - end - case "tc*" - if test $have_command = 0 - set have_command 1 - echo tcp_metrics - else - echo $word - end - case "to*" - if test $have_command = 0 - set have_command 1 - echo token - else - echo $word - end - case '-n' '-netns' '--netns' - if test $have_command = 0 - set skip 1 - else - echo $word - end - case '-*' - test $have_command = 0; and continue - echo $word - case '*' - if test $skip = 1 - set skip 0 - continue - end - echo $word - end - end - # Print an empty line if the current token is empty, so we know that the one before it is finished - # TODO: For some reason it is necessary to always print the current token - why doesn't the above loop catch it? - set -l token (commandline -ct) - echo $token + set -l skip 0 + set -l cmd (commandline -opc) + # HACK: Handle and/or/not specially because they have hardcoded completion behavior + # that doesn't remove them from the commandline + if contains -- $cmd[1] and or not + set -e cmd[1] + end + # Remove the first word because it's "ip" or an alias for it + set -e cmd[1] + set -l have_command 0 + for word in $cmd + switch $word + # Normalize the commands to their full form - `ip a` is `ip address` + # This can't be just an unambiguity check because there's also `ip addrlabel` + case a ad add addr addre addres address + # "addr add" is a thing, so we can only echo "address" if it's actually the command + if test $have_command = 0 + set have_command 1 + echo address + else + echo $word + end + case l li lin link + if test $have_command = 0 + set have_command 1 + echo link + else + echo $word + end + case "addrl*" + if test $have_command = 0 + set have_command 1 + echo addrlabel + else + echo $word + end + case r ro rou rout route + if test $have_command = 0 + set have_command 1 + echo route + else + echo $word + end + case "ru*" + if test $have_command = 0 + set have_command 1 + echo rule + else + echo $word + end + case n ne nei neig neigh + if test $have_command = 0 + set have_command 1 + echo neigh + else + echo $word + end + case nt + if test $have_command = 0 + set have_command 1 + echo ntable + else + echo $word + end + case t tu tun tunn tunne tunnel + if test $have_command = 0 + set have_command 1 + echo tunnel + else + echo $word + end + case "tunt*" + if test $have_command = 0 + set have_command 1 + echo tuntap + else + echo $word + end + case m ma mad madd maddr maddre maddres maddress + if test $have_command = 0 + set have_command 1 + echo maddress + else + echo $word + end + case mr "mro*" + if test $have_command = 0 + set have_command 1 + echo mroute + else + echo $word + end + case "mru*" + if test $have_command = 0 + set have_command 1 + echo mrule + else + echo $word + end + case "mo*" + if test $have_command = 0 + set have_command 1 + echo monitor + else + echo $word + end + case "x*" + if test $have_command = 0 + set have_command 1 + echo xfrm + else + echo $word + end + case "net*" + if test $have_command = 0 + set have_command 1 + echo netns + else + echo $word + end + case "l*" + if test $have_command = 0 + set have_command 1 + echo l2tp + else + echo $word + end + case "tc*" + if test $have_command = 0 + set have_command 1 + echo tcp_metrics + else + echo $word + end + case "to*" + if test $have_command = 0 + set have_command 1 + echo token + else + echo $word + end + case '-n' '-netns' '--netns' + if test $have_command = 0 + set skip 1 + else + echo $word + end + case '-*' + test $have_command = 0 + and continue + echo $word + case '*' + if test $skip = 1 + set skip 0 + continue + end + echo $word + end + end + # Print an empty line if the current token is empty, so we know that the one before it is finished + # TODO: For some reason it is necessary to always print the current token - why doesn't the above loop catch it? + set -l token (commandline -ct) + echo $token end function __fish_ip_device - ip -o link show | while read a b c - printf '%s\t%s\n' (string replace ':' '' -- $b) "Device" - end + ip -o link show | while read a b c + printf '%s\t%s\n' (string replace ':' '' -- $b) "Device" + end end function __fish_ip_scope - if test -r /etc/iproute2/rt_scopes - string replace -r '#.*' '' < /etc/iproute2/rt_scopes \ - | string match -v '^\s*$' \ - | string replace -r '(\S+)\s*(\S+)' '$1\t$2\n$2\t$1' \ - | string match -rv '^(global|link|host).*' # Ignore scopes with better descriptions - end - # Predefined scopes - printf '%s\t%s\n' global "Address is globally valid" \ - link "Address is link-local, only valid on this device" \ - host "Address is only valid on this host" + if test -r /etc/iproute2/rt_scopes + string replace -r '#.*' ''