Last Updated: February 25, 2016
·
1.48K
· danielstocks

Grabbing Your Local IP (Fish Shell)

Quite often I find myself running ifconfig in the terminal only to look through 30 or so lines in order to find out what my local IP address is on the current network.

Do yourself a favour and save this in .config/fish/functions/ip.fish

function ip
  ifconfig | grep "broadcast" | awk '{print $2}'
end

Picture
Disclaimer: This is only relevant for Mac OSX. I apologise to any non-OSX user ending up here.

You're welcome.

1 Response
Add your response

I use the following for my ip function in fish:

function :ip --description "Show ip info"
  set wan (curl -s http://ipecho.net/plain)
  set lan (ipconfig getifaddr en0)
  set domain (cat /etc/resolv.conf | grep domain | awk '{print $2}')
  set gateway (netstat -rn | grep default | awk '{print $2}')

  printf '%sLAN IP: %s%s%s\n' (set_color red) (set_color cyan) $lan (set_color normal)
  printf '%sWAN IP: %s%s%s\n' (set_color red) (set_color green) $wan (set_color normal)
  printf '%sDOMAIN : %s%s%s\n' (set_color red) (set_color green) $domain (set_color normal)
  printf '%sGATEWAY : %s%s%s\n' (set_color red) (set_color green) $gateway (set_color normal)
end
over 1 year ago ·