aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme21
1 files changed, 12 insertions, 9 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index ef945613..10d1564e 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -429,6 +429,7 @@ prompt_battery() {
prompt_public_ip() {
# set default values for segment
set_default POWERLEVEL9K_PUBLIC_IP_TIMOUT "300"
+ set_default POWERLEVEL9K_PUBLIC_IP_NONE ""
set_default POWERLEVEL9K_PUBLIC_IP_FILE "/tmp/p9k_public_ip"
set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me"
@@ -436,12 +437,11 @@ prompt_public_ip() {
local refresh_ip=false
if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
typeset -i timediff
+ # if saved IP is more than
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
+ [[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMOUT ]] && refresh_ip=true
+ # If tmp file is empty get a fresh IP
+ [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) || $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) =~ $POWERLEVEL9K_PUBLIC_IP_NONE ]] && refresh_ip=true
else
touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=true
fi
@@ -485,10 +485,12 @@ prompt_public_ip() {
fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
fi
fi
- [[ -n $fresh_ip ]] && echo $fresh_ip > $POWERLEVEL9K_PUBLIC_IP_FILE
+
+ # write IP to tmp file or clear tmp file if an IP was not retrieved
+ [[ -n $fresh_ip ]] && echo $fresh_ip > $POWERLEVEL9K_PUBLIC_IP_FILE || echo $POWERLEVEL9K_PUBLIC_IP_NONE > $POWERLEVEL9K_PUBLIC_IP_FILE
fi
- # write IP to tmp file
+ # read public IP saved to tmp file
local public_ip=$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)
if [[ -n $public_ip ]]; then
@@ -499,12 +501,13 @@ prompt_public_ip() {
# 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() {
+ set_default POWERLEVEL9K_CONTEXT_HOST_DEPTH "%m"
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
if [[ $(print -P "%#") == '#' ]]; then
# Shell runs as root
- "$1_prompt_segment" "$0_ROOT" "$2" "$DEFAULT_COLOR" "yellow" "$USER@%m"
+ "$1_prompt_segment" "$0_ROOT" "$2" "$DEFAULT_COLOR" "yellow" "$USER@$POWERLEVEL9K_CONTEXT_HOST_DEPTH"
else
- "$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@%m"
+ "$1_prompt_segment" "$0_DEFAULT" "$2" "$DEFAULT_COLOR" "011" "$USER@$POWERLEVEL9K_CONTEXT_HOST_DEPTH"
fi
fi
}