fish-shell/share/functions/__fish_print_addresses.fish
exploide 274be5eeeb added descriptions to __fish_print_addresses
added --all flag to include 0.0.0.0 and ::
adapted use of this function in existing completions
fixes #7787
2021-03-08 17:47:29 +01:00

16 lines
659 B
Fish

function __fish_print_addresses --description "List own network addresses with interface as description"
# if --all is given, also print 0.0.0.0 and ::
if contains -- --all $argv
echo -e "0.0.0.0\tall"
echo -e "::\tall"
end
if command -sq ip
command ip --oneline address | string replace -r '^\d+:\s+(\S+)\s+inet6?\s+([^\s/]+).*' '$2\t$1'
else if command -sq ifconfig
# This is for OSX/BSD
# There's also linux ifconfig but that has at least two different output formats
# is basically dead, and ip is installed on everything now
ifconfig | awk '/^\tinet/ { print $2 } '
end
end