mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
completions/ip: Restyle
Just run `fish_indent` on the entire thing.
This commit is contained in:
parent
15f089897d
commit
2d2f7c8fb1
@ -10,310 +10,311 @@ set -l ip_link l li lin link
|
|||||||
set -l ip_all_commands $ip_commands $ip_addr $ip_link
|
set -l ip_all_commands $ip_commands $ip_addr $ip_link
|
||||||
|
|
||||||
function __fish_ip_commandwords
|
function __fish_ip_commandwords
|
||||||
set -l skip 0
|
set -l skip 0
|
||||||
set -l cmd (commandline -opc)
|
set -l cmd (commandline -opc)
|
||||||
# HACK: Handle and/or/not specially because they have hardcoded completion behavior
|
# HACK: Handle and/or/not specially because they have hardcoded completion behavior
|
||||||
# that doesn't remove them from the commandline
|
# that doesn't remove them from the commandline
|
||||||
if contains -- $cmd[1] and or not
|
if contains -- $cmd[1] and or not
|
||||||
set -e cmd[1]
|
set -e cmd[1]
|
||||||
end
|
end
|
||||||
# Remove the first word because it's "ip" or an alias for it
|
# Remove the first word because it's "ip" or an alias for it
|
||||||
set -e cmd[1]
|
set -e cmd[1]
|
||||||
set -l have_command 0
|
set -l have_command 0
|
||||||
for word in $cmd
|
for word in $cmd
|
||||||
switch $word
|
switch $word
|
||||||
# Normalize the commands to their full form - `ip a` is `ip address`
|
# 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`
|
# This can't be just an unambiguity check because there's also `ip addrlabel`
|
||||||
case a ad add addr addre addres address
|
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
|
# "addr add" is a thing, so we can only echo "address" if it's actually the command
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo address
|
echo address
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case l li lin link
|
case l li lin link
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo link
|
echo link
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "addrl*"
|
case "addrl*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo addrlabel
|
echo addrlabel
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case r ro rou rout route
|
case r ro rou rout route
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo route
|
echo route
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "ru*"
|
case "ru*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo rule
|
echo rule
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case n ne nei neig neigh
|
case n ne nei neig neigh
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo neigh
|
echo neigh
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case nt
|
case nt
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo ntable
|
echo ntable
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case t tu tun tunn tunne tunnel
|
case t tu tun tunn tunne tunnel
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo tunnel
|
echo tunnel
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "tunt*"
|
case "tunt*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo tuntap
|
echo tuntap
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case m ma mad madd maddr maddre maddres maddress
|
case m ma mad madd maddr maddre maddres maddress
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo maddress
|
echo maddress
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case mr "mro*"
|
case mr "mro*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo mroute
|
echo mroute
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "mru*"
|
case "mru*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo mrule
|
echo mrule
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "mo*"
|
case "mo*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo monitor
|
echo monitor
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "x*"
|
case "x*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo xfrm
|
echo xfrm
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "net*"
|
case "net*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo netns
|
echo netns
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "l*"
|
case "l*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo l2tp
|
echo l2tp
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "tc*"
|
case "tc*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo tcp_metrics
|
echo tcp_metrics
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case "to*"
|
case "to*"
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set have_command 1
|
set have_command 1
|
||||||
echo token
|
echo token
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case '-n' '-netns' '--netns'
|
case '-n' '-netns' '--netns'
|
||||||
if test $have_command = 0
|
if test $have_command = 0
|
||||||
set skip 1
|
set skip 1
|
||||||
else
|
else
|
||||||
echo $word
|
echo $word
|
||||||
end
|
end
|
||||||
case '-*'
|
case '-*'
|
||||||
test $have_command = 0; and continue
|
test $have_command = 0
|
||||||
echo $word
|
and continue
|
||||||
case '*'
|
echo $word
|
||||||
if test $skip = 1
|
case '*'
|
||||||
set skip 0
|
if test $skip = 1
|
||||||
continue
|
set skip 0
|
||||||
end
|
continue
|
||||||
echo $word
|
end
|
||||||
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
|
end
|
||||||
# TODO: For some reason it is necessary to always print the current token - why doesn't the above loop catch it?
|
# Print an empty line if the current token is empty, so we know that the one before it is finished
|
||||||
set -l token (commandline -ct)
|
# TODO: For some reason it is necessary to always print the current token - why doesn't the above loop catch it?
|
||||||
echo $token
|
set -l token (commandline -ct)
|
||||||
|
echo $token
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fish_ip_device
|
function __fish_ip_device
|
||||||
ip -o link show | while read a b c
|
ip -o link show | while read a b c
|
||||||
printf '%s\t%s\n' (string replace ':' '' -- $b) "Device"
|
printf '%s\t%s\n' (string replace ':' '' -- $b) "Device"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fish_ip_scope
|
function __fish_ip_scope
|
||||||
if test -r /etc/iproute2/rt_scopes
|
if test -r /etc/iproute2/rt_scopes
|
||||||
string replace -r '#.*' '' < /etc/iproute2/rt_scopes \
|
string replace -r '#.*' '' </etc/iproute2/rt_scopes \
|
||||||
| string match -v '^\s*$' \
|
| string match -v '^\s*$' \
|
||||||
| string replace -r '(\S+)\s*(\S+)' '$1\t$2\n$2\t$1' \
|
| string replace -r '(\S+)\s*(\S+)' '$1\t$2\n$2\t$1' \
|
||||||
| string match -rv '^(global|link|host).*' # Ignore scopes with better descriptions
|
| string match -rv '^(global|link|host).*' # Ignore scopes with better descriptions
|
||||||
end
|
end
|
||||||
# Predefined scopes
|
# Predefined scopes
|
||||||
printf '%s\t%s\n' global "Address is globally valid" \
|
printf '%s\t%s\n' global "Address is globally valid" \
|
||||||
link "Address is link-local, only valid on this device" \
|
link "Address is link-local, only valid on this device" \
|
||||||
host "Address is only valid on this host"
|
host "Address is only valid on this host"
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fish_ip_types
|
function __fish_ip_types
|
||||||
printf '%s\t%s\n' \
|
printf '%s\t%s\n' \
|
||||||
macvtap "Virtual interface based on link layer address (MAC) and TAP." \
|
macvtap "Virtual interface based on link layer address (MAC) and TAP." \
|
||||||
vcan "Virtual Controller Area Network interface" \
|
vcan "Virtual Controller Area Network interface" \
|
||||||
veth "Virtual ethernet interface" \
|
veth "Virtual ethernet interface" \
|
||||||
vlan "802.1q tagged virtual LAN interface" \
|
vlan "802.1q tagged virtual LAN interface" \
|
||||||
vxlan "Virtual eXtended LAN" \
|
vxlan "Virtual eXtended LAN" \
|
||||||
ip6tnl "Virtual tunnel interface IPv4|IPv6 over IPv6" \
|
ip6tnl "Virtual tunnel interface IPv4|IPv6 over IPv6" \
|
||||||
ipip "Virtual tunnel interface IPv4 over IPv4" \
|
ipip "Virtual tunnel interface IPv4 over IPv4" \
|
||||||
sit "Virtual tunnel interface IPv6 over IPv4" \
|
sit "Virtual tunnel interface IPv6 over IPv4" \
|
||||||
gre "Virtual tunnel interface GRE over IPv4" \
|
gre "Virtual tunnel interface GRE over IPv4" \
|
||||||
gretap "Virtual L2 tunnel interface GRE over IPv4" \
|
gretap "Virtual L2 tunnel interface GRE over IPv4" \
|
||||||
ip6gre "Virtual tunnel interface GRE over IPv6" \
|
ip6gre "Virtual tunnel interface GRE over IPv6" \
|
||||||
ip6gretap "Virtual L2 tunnel interface GRE over IPv6" \
|
ip6gretap "Virtual L2 tunnel interface GRE over IPv6" \
|
||||||
vti "Virtual tunnel interface" \
|
vti "Virtual tunnel interface" \
|
||||||
nlmon "Netlink monitoring device" \
|
nlmon "Netlink monitoring device" \
|
||||||
ipvlan "Interface for L3 (IPv6/IPv4) based VLANs" \
|
ipvlan "Interface for L3 (IPv6/IPv4) based VLANs" \
|
||||||
lowpan "Interface for 6LoWPAN (IPv6) over IEEE 802.15.4 / Bluetooth" \
|
lowpan "Interface for 6LoWPAN (IPv6) over IEEE 802.15.4 / Bluetooth" \
|
||||||
geneve "GEneric NEtwork Virtualization Encapsulation"
|
geneve "GEneric NEtwork Virtualization Encapsulation"
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fish_complete_ip
|
function __fish_complete_ip
|
||||||
set -l cmd (__fish_ip_commandwords)
|
set -l cmd (__fish_ip_commandwords)
|
||||||
set -l count (count $cmd)
|
set -l count (count $cmd)
|
||||||
switch "$cmd[1]"
|
switch "$cmd[1]"
|
||||||
case address
|
case address
|
||||||
# We're still _on_ the second word, which is the subcommand
|
# We're still _on_ the second word, which is the subcommand
|
||||||
if not set -q cmd[3]
|
if not set -q cmd[3]
|
||||||
printf '%s\t%s\n' add "Add new protocol address" \
|
printf '%s\t%s\n' add "Add new protocol address" \
|
||||||
delete "Delete protocol address" \
|
delete "Delete protocol address" \
|
||||||
show "Look at protocol addresses" \
|
show "Look at protocol addresses" \
|
||||||
flush "Flush protocol addresses"
|
flush "Flush protocol addresses"
|
||||||
else
|
else
|
||||||
switch $cmd[2]
|
switch $cmd[2]
|
||||||
# Change and replace are undocumented (apart from mentions in the BNF)
|
# Change and replace are undocumented (apart from mentions in the BNF)
|
||||||
case add change replace
|
case add change replace
|
||||||
switch $count
|
switch $count
|
||||||
case 3
|
case 3
|
||||||
# __fish_ip_complete_ip
|
# __fish_ip_complete_ip
|
||||||
case '*'
|
case '*'
|
||||||
switch $cmd[-2]
|
switch $cmd[-2]
|
||||||
case dev
|
case dev
|
||||||
__fish_ip_device
|
__fish_ip_device
|
||||||
case scope
|
case scope
|
||||||
__fish_ip_scope
|
__fish_ip_scope
|
||||||
# TODO: Figure out how to complete these
|
# TODO: Figure out how to complete these
|
||||||
case label
|
case label
|
||||||
# Prefix
|
# Prefix
|
||||||
case local peer broadcast
|
case local peer broadcast
|
||||||
# Address
|
# Address
|
||||||
case valid_lft preferred_lft
|
case valid_lft preferred_lft
|
||||||
# Lifetime
|
# Lifetime
|
||||||
case '*'
|
case '*'
|
||||||
printf '%s\t%s\n' forever "Keep address valid forever" \
|
printf '%s\t%s\n' forever "Keep address valid forever" \
|
||||||
home "(Ipv6 only) Designate address as home adress" \
|
home "(Ipv6 only) Designate address as home adress" \
|
||||||
nodad "(Ipv6 only) Don't perform duplicate address detection" \
|
nodad "(Ipv6 only) Don't perform duplicate address detection" \
|
||||||
dev "Add address to specified device" \
|
dev "Add address to specified device" \
|
||||||
scope "Set scope of address" \
|
scope "Set scope of address" \
|
||||||
label "Tag address with label"
|
label "Tag address with label"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
case delete
|
case delete
|
||||||
switch $count
|
switch $count
|
||||||
case 3
|
case 3
|
||||||
ip -o addr show | while read a b c d e
|
ip -o addr show | while read a b c d e
|
||||||
echo $d
|
echo $d
|
||||||
end
|
end
|
||||||
case 4
|
case 4
|
||||||
# A dev argument is mandatory, but contrary to the BNF, other things (like "scope") are also valid here
|
# A dev argument is mandatory, but contrary to the BNF, other things (like "scope") are also valid here
|
||||||
# And yes, unlike e.g. show, this _needs_ the "dev" before the device
|
# And yes, unlike e.g. show, this _needs_ the "dev" before the device
|
||||||
# Otherwise it barfs and says "??? prefix is expected"
|
# Otherwise it barfs and says "??? prefix is expected"
|
||||||
# Anyway, try to steer the user towards supplying a device
|
# Anyway, try to steer the user towards supplying a device
|
||||||
echo dev
|
echo dev
|
||||||
case 5
|
case 5
|
||||||
switch $cmd[-2]
|
switch $cmd[-2]
|
||||||
case dev
|
case dev
|
||||||
ip -o addr show | string match "*$cmd[3]*" | while read a b c
|
ip -o addr show | string match "*$cmd[3]*" | while read a b c
|
||||||
echo $b
|
echo $b
|
||||||
end
|
end
|
||||||
# TODO: Moar
|
# TODO: Moar
|
||||||
end
|
end
|
||||||
case show save flush # These take the same args
|
case show save flush # These take the same args
|
||||||
switch $cmd[-2]
|
switch $cmd[-2]
|
||||||
case dev
|
case dev
|
||||||
__fish_ip_device
|
__fish_ip_device
|
||||||
case scope
|
case scope
|
||||||
__fish_ip_scope
|
__fish_ip_scope
|
||||||
case to
|
case to
|
||||||
# Prefix
|
# Prefix
|
||||||
case label
|
case label
|
||||||
# Label-pattern
|
# Label-pattern
|
||||||
case '*'
|
case '*'
|
||||||
printf '%s\t%s\n' up "Only active devices" \
|
printf '%s\t%s\n' up "Only active devices" \
|
||||||
dev "Limit to a certain device" \
|
dev "Limit to a certain device" \
|
||||||
scope "Limit scope" \
|
scope "Limit scope" \
|
||||||
to "Limit prefix" \
|
to "Limit prefix" \
|
||||||
label "Limit by label" \
|
label "Limit by label" \
|
||||||
dynamic "(Ipv6 only) Limit to dynamic addresses" \
|
dynamic "(Ipv6 only) Limit to dynamic addresses" \
|
||||||
permanent "(Ipv6 only) Limit to permanent addresses"
|
permanent "(Ipv6 only) Limit to permanent addresses"
|
||||||
__fish_ip_device
|
__fish_ip_device
|
||||||
# TODO: Moar
|
# TODO: Moar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
case link
|
case link
|
||||||
if not set -q cmd[3]
|
if not set -q cmd[3]
|
||||||
printf '%s\t%s\n' add "Add virtual link" \
|
printf '%s\t%s\n' add "Add virtual link" \
|
||||||
delete "Delete virtual link" \
|
delete "Delete virtual link" \
|
||||||
set "Change device attributes" \
|
set "Change device attributes" \
|
||||||
show "Display device attributes" \
|
show "Display device attributes" \
|
||||||
help "Display help"
|
help "Display help"
|
||||||
else
|
else
|
||||||
# TODO: Add moar
|
# TODO: Add moar
|
||||||
switch $cmd[2]
|
switch $cmd[2]
|
||||||
case add
|
case add
|
||||||
switch $cmd[-2]
|
switch $cmd[-2]
|
||||||
case link
|
case link
|
||||||
__fish_ip_device
|
__fish_ip_device
|
||||||
case name # freeform, uncompleteable.
|
case name # freeform, uncompleteable.
|
||||||
case type
|
case type
|
||||||
__fish_ip_types
|
__fish_ip_types
|
||||||
case txqueuelen
|
case txqueuelen
|
||||||
case address
|
case address
|
||||||
@ -325,21 +326,21 @@ function __fish_complete_ip
|
|||||||
# We assume if we haven't checked it above, we're back to `ip link add`, with any optionals completed.
|
# We assume if we haven't checked it above, we're back to `ip link add`, with any optionals completed.
|
||||||
# So we now suggest optionals.
|
# So we now suggest optionals.
|
||||||
printf '%s\t%s\n' \
|
printf '%s\t%s\n' \
|
||||||
link "" \
|
link "" \
|
||||||
type "" \
|
type "" \
|
||||||
txqueuelen PACKETS \
|
txqueuelen PACKETS \
|
||||||
address LLADDR \
|
address LLADDR \
|
||||||
broadcast LLADDR \
|
broadcast LLADDR \
|
||||||
mtu MTU \
|
mtu MTU \
|
||||||
index IDX \
|
index IDX \
|
||||||
numtxqueues QUEUE_COUNT \
|
numtxqueues QUEUE_COUNT \
|
||||||
numrxqueues QUEUE_COUNT \
|
numrxqueues QUEUE_COUNT \
|
||||||
gso_max_size BYTES \
|
gso_max_size BYTES \
|
||||||
gso_max_segs
|
gso_max_segs
|
||||||
end
|
end
|
||||||
case delete
|
case delete
|
||||||
case set
|
case set
|
||||||
switch $cmd[-2]
|
switch $cmd[-2]
|
||||||
case type
|
case type
|
||||||
__fish_ip_types
|
__fish_ip_types
|
||||||
echo bridge_slave
|
echo bridge_slave
|
||||||
@ -374,11 +375,11 @@ function __fish_complete_ip
|
|||||||
echo up
|
echo up
|
||||||
echo down
|
echo down
|
||||||
end
|
end
|
||||||
case show
|
case show
|
||||||
case help
|
case help
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
complete -f -c ip
|
complete -f -c ip
|
||||||
|
Loading…
x
Reference in New Issue
Block a user