Last Updated: February 25, 2016
·
481
· nvk

Local and External IPs — beautified

Local and External IPs — beautified

Simple ZSH script to get the external and local IPs

Screen Shot

IPs script

ip(){
    hrline 36

    # Gets external IP from opendns.com
    print -P      "%F{240}|%f  %F{$colorInfo}=> External IP%f  `dig +short myip.opendns.com @resolver1.opendns.com`  %F{240}|%f" 

    # Get's local IP from ipconfig
    print -P "%F{240}|%f  %F{$colorSecondary}=> Local IP   %f  `ipconfig getifaddr en0`    %F{240}|%f" 

    # make line, https://gist.github.com/nvk/5340820
    hrline 36
}

</code>

Gist Link

Makes dash "-" lines on demand.

hrline() {

    # Checks for stout if none gives a default number
    if [ -z "$1" ]
    then
        local length=50
    else
        local length="$1"
    fi

    # Takes stout and uses as length
    for i in `seq $length`; do hrline="$hrline-";done

    # Prints with ZSH colors
    print -P "%F{240}$hrline%f"

    # Clears var
    hrline=""
}

</code>

Gist Link