From 3e9975c4386d578c238735ad517c914fdbe2fd5e Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 9 Feb 2016 09:36:43 +1100 Subject: [PATCH 1/6] Add local IP support to Linux and Windows --- fetch | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/fetch b/fetch index 77ca216e..d4ecc3a7 100755 --- a/fetch +++ b/fetch @@ -1335,6 +1335,26 @@ getbattery () { # }}} +# IP Address {{{ + +getlocalip () { + case "$os" in + "Linux") + localip="$(ip route get 1 | awk '{print $NF;exit}')" + ;; + + "Windows") + localip="$(ipconfig | awk -F ': ' '/IPv4 Address/ {printf $2}')" + ;; + + *) + localip="Unknown" + ;; + esac +} + +# }}} + # Birthday {{{ getbirthday () { From 2f13ce79de4db031bb92c37f0bb5f84d1ca51315 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 9 Feb 2016 10:48:37 +1100 Subject: [PATCH 2/6] Added local IP support to OS X --- fetch | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fetch b/fetch index d4ecc3a7..7ce5d776 100755 --- a/fetch +++ b/fetch @@ -1343,6 +1343,11 @@ getlocalip () { localip="$(ip route get 1 | awk '{print $NF;exit}')" ;; + "Mac OS X") + localip="$(ipconfig getifaddr en0)" + [ -z "$localip" ] && localip="$(ipconfig getifaddr en1)" + ;; + "Windows") localip="$(ipconfig | awk -F ': ' '/IPv4 Address/ {printf $2}')" ;; From 609e18a31c7cb1c01b420bd2416e9cf67a62a8cd Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 9 Feb 2016 17:20:19 +1100 Subject: [PATCH 3/6] Add 'publicip' command to display your public ip address. --- fetch | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fetch b/fetch index 7ce5d776..8dd28e49 100755 --- a/fetch +++ b/fetch @@ -1358,6 +1358,18 @@ getlocalip () { esac } +getpublicip () { + if type -p curl >/dev/null 2>&1; then + publicip="$(curl -w '\n' http://ident.me)" + + elif type -p wget >/dev/null 2>&1; then + publicip="$(wget -qO- http://ident.me; printf "%s")" + + else + publicip="Unknown" + fi +} + # }}} # Birthday {{{ From 76d583a124bf1bdb998318255fee66ad70d81e11 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 9 Feb 2016 17:26:44 +1100 Subject: [PATCH 4/6] Added '--ip_host' and '' which allow you to choose which website to ping for the public ip --- README.md | 3 +-- config/config | 7 +++++++ fetch | 13 +++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3b8d77a2..3bfe898f 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,7 @@ alias fetch2="fetch \ --shell_version on/off Enable/Disable showing \$SHELL version --battery_num num Which battery to display, default value is 'all' --battery_shorthand on/off Whether or not each battery gets its own line/title + --ip_host url Url to ping for public IP --birthday_shorthand on/off Shorten the output of birthday --birthday_time on/off Enable/Disable showing the time in birthday output @@ -273,8 +274,6 @@ alias fetch2="fetch \ --shuffle_dir path/to/dir Which directory to shuffle for an image. --font_width px Used to automatically size the image --image_position left/right Where to display the image: (Left/Right) - --split_size num Width of img/text splits, A value of 2 makes each - split half the terminal width and etc. --crop_mode mode Which crop mode to use Takes the values: normal, fit, fill --crop_offset value Change the crop offset for normal mode. diff --git a/config/config b/config/config index 60d8d4c8..56ebf4e0 100644 --- a/config/config +++ b/config/config @@ -130,6 +130,13 @@ battery_num="all" battery_shorthand="off" +# IP Address + +# Website to ping for the public IP +# --ip_host url +public_ip_host="http://ident.me" + + # Birthday # Whether to show a long pretty output diff --git a/fetch b/fetch index 8dd28e49..514ddcc4 100755 --- a/fetch +++ b/fetch @@ -150,6 +150,13 @@ battery_num="all" battery_shorthand="off" +# IP Address + +# Website to ping for the public IP +# --ip_host url +public_ip_host="http://ident.me" + + # Birthday # Whether to show a long pretty output @@ -1360,10 +1367,10 @@ getlocalip () { getpublicip () { if type -p curl >/dev/null 2>&1; then - publicip="$(curl -w '\n' http://ident.me)" + publicip="$(curl -w '\n' "$public_ip_host")" elif type -p wget >/dev/null 2>&1; then - publicip="$(wget -qO- http://ident.me; printf "%s")" + publicip="$(wget -qO- "$public_ip_host"; printf "%s")" else publicip="Unknown" @@ -2151,6 +2158,7 @@ usage () { cat << EOF --shell_version on/off Enable/Disable showing \$SHELL version --battery_num num Which battery to display, default value is 'all' --battery_shorthand on/off Whether or not each battery gets its own line/title + --ip_host url Url to ping for public IP --birthday_shorthand on/off Shorten the output of birthday --birthday_time on/off Enable/Disable showing the time in birthday output @@ -2255,6 +2263,7 @@ while [ "$1" ]; do --shell_version) shell_version="$2" ;; --battery_num) battery_num="$2" ;; --battery_shorthand) battery_shorthand="$2" ;; + --ip_host) public_ip_host="$2" ;; --birthday_shorthand) birthday_shorthand="$2" ;; --birthday_time) birthday_time="$2" ;; --disable) From 111caa6356aa9232e289647e113078df0fb68f67 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 9 Feb 2016 17:53:52 +1100 Subject: [PATCH 5/6] Add experimental and untested BSD support to localip --- fetch | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fetch b/fetch index 514ddcc4..bbc7071a 100755 --- a/fetch +++ b/fetch @@ -1355,6 +1355,11 @@ getlocalip () { [ -z "$localip" ] && localip="$(ipconfig getifaddr en1)" ;; + *"BSD") + localip="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' \ + | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')" + ;; + "Windows") localip="$(ipconfig | awk -F ': ' '/IPv4 Address/ {printf $2}')" ;; From 7ec516860a88311889436814c2576911120b2c45 Mon Sep 17 00:00:00 2001 From: Dylan Date: Tue, 9 Feb 2016 18:32:01 +1100 Subject: [PATCH 6/6] Replace broken BSD local ip cmd with a tested working one --- fetch | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fetch b/fetch index bbc7071a..3d4420d3 100755 --- a/fetch +++ b/fetch @@ -1356,8 +1356,7 @@ getlocalip () { ;; *"BSD") - localip="$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' \ - | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1')" + localip="$(ifconfig | awk '/broadcast/ {print $2}')" ;; "Windows")