diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 4f09c515..c8ccf574 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -3,11 +3,50 @@ about-plugin 'miscellaneous tools' function ips () { - about 'display all ip addresses for this host' + about 'display all IPv4/6 addresses for this host' group 'base' - ifconfig | grep "inet " | awk '{ print $2 }' + + mode=4 + if [ -n "$1" ]; then + case "$1" in + -4) ;; + -6) mode=6 ;; + -a) mode=both ;; + -h) echo "Usage ips [-4|-6|-a]" + echo " -4 list only IPv4 addresses" + echo " -6 list only IPv6 addresses" + echo " -a list both IPv4 and IPv6 addresses" + return + ;; + *) echo "Illegal option $1" + echo "Only -4, -6 and -a options are allowed" + return 1 + ;; + esac + fi + + token="inet" + case $mode in + 4) ;; + 6) token="${token}6" ;; + both) token="${token}6?" ;; + esac + case "$OSTYPE" in + darwin*) + ifconfig | grep -E "${token} " | awk '{ print $2 }' + ;; + + # ifconfig is not available for users on modern linux distributions, + # also it uses a slightly different format. + # Use ip instead. + linux*) + ip ad | grep -E "${token} " | awk '{ sub(/\/.*$/,"",$2); print $2}' + ;; + esac } +alias ips6='ips -6' + function down4me () { about 'checks whether a website is down for you, or everybody'