From f7e8f8031da7f0f4f6e17fb5443a6358ec5a8e6c Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 16 Sep 2015 23:01:27 +0200 Subject: __fish_print_{addresses,interfaces}: Add alternative to net_tools net_tools, which provides `ifconfig` and `netstat`, among other things, has last been updated in 2013. This means `ifconfig` on linux is basically dead. Instead of ifconfig, use `ip` (from iproute2), which is much more powerful and provides a much more annoying commandline syntax. Instead of netstat, just look at /sys/class/net. --- share/functions/__fish_print_addresses.fish | 6 +++++- share/functions/__fish_print_interfaces.fish | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/share/functions/__fish_print_addresses.fish b/share/functions/__fish_print_addresses.fish index 4311b1e8..578c9f63 100644 --- a/share/functions/__fish_print_addresses.fish +++ b/share/functions/__fish_print_addresses.fish @@ -1,4 +1,8 @@ function __fish_print_addresses --description "Print a list of known network addresses" - /sbin/ifconfig | __fish_sgrep 'inet addr'|cut -d : -f 2|cut -d ' ' -f 1 + if command -s ip >/dev/null + command ip --oneline address | cut -d" " -f7 | sed "s:\(.*\)/.*:\1:" + else if command -s ifconfig >/dev/null + command ifconfig |sgrep 'inet addr'|cut -d : -f 2|cut -d ' ' -f 1 + end end diff --git a/share/functions/__fish_print_interfaces.fish b/share/functions/__fish_print_interfaces.fish index cf100056..d9805359 100644 --- a/share/functions/__fish_print_interfaces.fish +++ b/share/functions/__fish_print_interfaces.fish @@ -1,3 +1,10 @@ function __fish_print_interfaces --description "Print a list of known network interfaces" - netstat -i -n -a | awk 'NR>2'|awk '{print $1}' + if test -d /sys/class/net + cd /sys/class/net + for i in * + echo $i + end + else + netstat -i -n -a | awk 'NR>2'|awk '{print $1}' + end end -- cgit v1.2.3 From b34127e3466de2239b9425ad0d5a68282a174cc4 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Fri, 18 Sep 2015 12:00:12 +0200 Subject: __fish_print_{addresses,interaces}: Better OSX/BSD --- share/functions/__fish_print_addresses.fish | 5 ++++- share/functions/__fish_print_interfaces.fish | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/share/functions/__fish_print_addresses.fish b/share/functions/__fish_print_addresses.fish index 578c9f63..fd8c6035 100644 --- a/share/functions/__fish_print_addresses.fish +++ b/share/functions/__fish_print_addresses.fish @@ -2,7 +2,10 @@ function __fish_print_addresses --description "Print a list of known network add if command -s ip >/dev/null command ip --oneline address | cut -d" " -f7 | sed "s:\(.*\)/.*:\1:" else if command -s ifconfig >/dev/null - command ifconfig |sgrep 'inet addr'|cut -d : -f 2|cut -d ' ' -f 1 + # 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 diff --git a/share/functions/__fish_print_interfaces.fish b/share/functions/__fish_print_interfaces.fish index d9805359..bb3dbbd9 100644 --- a/share/functions/__fish_print_interfaces.fish +++ b/share/functions/__fish_print_interfaces.fish @@ -4,7 +4,7 @@ function __fish_print_interfaces --description "Print a list of known network in for i in * echo $i end - else - netstat -i -n -a | awk 'NR>2'|awk '{print $1}' + else # OSX/BSD + command ifconfig -l | tr ' ' '\n' end end -- cgit v1.2.3