2021-03-07 18:03:28 +08:00
|
|
|
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
|
2017-02-14 00:30:38 +08:00
|
|
|
if command -sq ip
|
2021-03-07 18:03:28 +08:00
|
|
|
command ip --oneline address | string replace -r '^\d+:\s+(\S+)\s+inet6?\s+([^\s/]+).*' '$2\t$1'
|
2017-02-14 00:30:38 +08:00
|
|
|
else if command -sq ifconfig
|
2016-11-28 13:27:22 +08:00
|
|
|
# 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
|
2007-09-22 04:52:12 +08:00
|
|
|
end
|