From 29233c1963ce85241972e7962b92c73535e4a1d6 Mon Sep 17 00:00:00 2001
From: rjorgenson <rjorgenson@gmail.com>
Date: Fri, 30 Dec 2016 14:04:18 -0700
Subject: added public IP segment for review/discussion

---
 functions/icons.zsh    |  5 ++++-
 powerlevel9k.zsh-theme | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/functions/icons.zsh b/functions/icons.zsh
index 06d6ab20..b13e3463 100644
--- a/functions/icons.zsh
+++ b/functions/icons.zsh
@@ -76,6 +76,7 @@ case $POWERLEVEL9K_MODE in
       RUST_ICON                      ''
       PYTHON_ICON                    $'\U1F40D'             # 🐍
       SWIFT_ICON                     ''
+      PUBLIC_IP_ICON                 ''
     )
   ;;
   'awesome-fontconfig')
@@ -131,9 +132,10 @@ case $POWERLEVEL9K_MODE in
       VCS_GIT_GITLAB_ICON            $'\uF296 '             # 
       VCS_HG_ICON                    $'\uF0C3 '             # 
       VCS_SVN_ICON                   '(svn) '
-      RUST_ICON                      $'\uE6A8'              #  
+      RUST_ICON                      $'\uE6A8'              # 
       PYTHON_ICON                    $'\U1F40D'             # 🐍
       SWIFT_ICON                     ''
+      PUBLIC_IP_ICON                 ''
     )
   ;;
   *)
@@ -192,6 +194,7 @@ case $POWERLEVEL9K_MODE in
       RUST_ICON                      ''
       PYTHON_ICON                    ''
       SWIFT_ICON                     'Swift'
+      PUBLIC_IP_ICON                 ''
     )
   ;;
 esac
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 9ea12aa7..34d1f640 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -426,6 +426,51 @@ prompt_battery() {
   fi
 }
 
+prompt_public_ip() {
+  # set default values for segment
+  set_default POWERLEVEL9K_PUBLIC_IP_TIMOUT "300"
+  set_default POWERLEVEL9K_PUBLIC_IP_FILE "/tmp/p9k_public_ip"
+  set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me"
+
+  # Do we need a fresh IP?
+  local refresh_ip=FALSE
+  if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
+    typeset -i timediff
+    timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
+    [[ $timediff -gt '500' ]] && refresh_ip=TRUE
+    # this will run the IP refresh with each new prompt while disconnected
+    # but will get a new IP immediately once reconnected rather than waiting
+    # for the timeout, not sure if this is ideal behavior or not
+    [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=TRUE
+  else
+    touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=TRUE
+  fi
+
+  # grab a fresh IP if needed
+  if [[ $refresh_ip =~ 'TRUE' && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
+    if type -p dig >/dev/null; then
+        fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)"
+        [[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip
+    fi
+
+    if [[ -z "$fresh_ip" ]] && type -p curl >/dev/null; then
+        fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
+    fi
+
+    if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then
+        fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
+    fi
+    [[ -n $fresh_ip ]] && echo $fresh_ip > $POWERLEVEL9K_PUBLIC_IP_FILE
+  fi
+
+  # write IP to tmp file
+  local public_ip=$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)
+
+  if [[ -n $public_ip ]]; then
+    $1_prompt_segment "$0" "$2" "black" "249" "${public_ip}" 'PUBLIC_IP_ICON'
+  fi
+}
+
 # Context: user@hostname (who am I and where am I)
 # Note that if $DEFAULT_USER is not set, this prompt segment will always print
 prompt_context() {
-- 
cgit v1.2.3


From 2ddf2a2f2039e6f800be620e5d82b94c68019364 Mon Sep 17 00:00:00 2001
From: rjorgenson <rjorgenson@gmail.com>
Date: Fri, 30 Dec 2016 14:09:43 -0700
Subject: fixed colors to defaults

---
 powerlevel9k.zsh-theme | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 34d1f640..65d3b11d 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -467,7 +467,7 @@ prompt_public_ip() {
   local public_ip=$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)
 
   if [[ -n $public_ip ]]; then
-    $1_prompt_segment "$0" "$2" "black" "249" "${public_ip}" 'PUBLIC_IP_ICON'
+    $1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" 'PUBLIC_IP_ICON'
   fi
 }
 
-- 
cgit v1.2.3


From fa21bfff4595eb9451917ed219d29b83ea74c2e4 Mon Sep 17 00:00:00 2001
From: rjorgenson <rjorgenson@gmail.com>
Date: Fri, 30 Dec 2016 14:10:43 -0700
Subject: reverted trailing space edit

---
 functions/icons.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/functions/icons.zsh b/functions/icons.zsh
index b13e3463..77015f0b 100644
--- a/functions/icons.zsh
+++ b/functions/icons.zsh
@@ -132,7 +132,7 @@ case $POWERLEVEL9K_MODE in
       VCS_GIT_GITLAB_ICON            $'\uF296 '             # 
       VCS_HG_ICON                    $'\uF0C3 '             # 
       VCS_SVN_ICON                   '(svn) '
-      RUST_ICON                      $'\uE6A8'              # 
+      RUST_ICON                      $'\uE6A8'              #  
       PYTHON_ICON                    $'\U1F40D'             # 🐍
       SWIFT_ICON                     ''
       PUBLIC_IP_ICON                 ''
-- 
cgit v1.2.3


From cf88f861fa29d0d78ca08c7f831717945abb94eb Mon Sep 17 00:00:00 2001
From: rjorgenson <rjorgenson@gmail.com>
Date: Sun, 1 Jan 2017 23:47:01 -0700
Subject: fixed boolean values

---
 powerlevel9k.zsh-theme | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 65d3b11d..437a1fb1 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -433,21 +433,21 @@ prompt_public_ip() {
   set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me"
 
   # Do we need a fresh IP?
-  local refresh_ip=FALSE
+  local refresh_ip=false
   if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
     typeset -i timediff
     timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
-    [[ $timediff -gt '500' ]] && refresh_ip=TRUE
+    [[ $timediff -gt '500' ]] && refresh_ip=true
     # this will run the IP refresh with each new prompt while disconnected
     # but will get a new IP immediately once reconnected rather than waiting
     # for the timeout, not sure if this is ideal behavior or not
-    [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=TRUE
+    [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true
   else
-    touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=TRUE
+    touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=true
   fi
 
   # grab a fresh IP if needed
-  if [[ $refresh_ip =~ 'TRUE' && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
+  if [[ $refresh_ip =~ true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
     if type -p dig >/dev/null; then
         fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)"
         [[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip
-- 
cgit v1.2.3