|
|
@ -429,6 +429,7 @@ prompt_battery() {
|
|
|
|
prompt_public_ip() {
|
|
|
|
prompt_public_ip() {
|
|
|
|
# set default values for segment
|
|
|
|
# set default values for segment
|
|
|
|
set_default POWERLEVEL9K_PUBLIC_IP_TIMOUT "300"
|
|
|
|
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_FILE "/tmp/p9k_public_ip"
|
|
|
|
set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me"
|
|
|
|
set_default POWERLEVEL9K_PUBLIC_IP_HOST "http://ident.me"
|
|
|
|
|
|
|
|
|
|
|
@ -436,12 +437,11 @@ prompt_public_ip() {
|
|
|
|
local refresh_ip=false
|
|
|
|
local refresh_ip=false
|
|
|
|
if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
|
|
|
|
if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then
|
|
|
|
typeset -i timediff
|
|
|
|
typeset -i timediff
|
|
|
|
|
|
|
|
# if saved IP is more than
|
|
|
|
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
|
|
|
|
timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s)))
|
|
|
|
[[ $timediff -gt '500' ]] && refresh_ip=true
|
|
|
|
[[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMOUT ]] && refresh_ip=true
|
|
|
|
# this will run the IP refresh with each new prompt while disconnected
|
|
|
|
# If tmp file is empty get a fresh IP
|
|
|
|
# but will get a new IP immediately once reconnected rather than waiting
|
|
|
|
[[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) || $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) =~ $POWERLEVEL9K_PUBLIC_IP_NONE ]] && refresh_ip=true
|
|
|
|
# for the timeout, not sure if this is ideal behavior or not
|
|
|
|
|
|
|
|
[[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true
|
|
|
|
|
|
|
|
else
|
|
|
|
else
|
|
|
|
touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=true
|
|
|
|
touch $POWERLEVEL9K_PUBLIC_IP_FILE && refresh_ip=true
|
|
|
|
fi
|
|
|
|
fi
|
|
|
@ -485,10 +485,12 @@ prompt_public_ip() {
|
|
|
|
fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
|
|
|
|
fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
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
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# write IP to tmp file
|
|
|
|
# read public IP saved to tmp file
|
|
|
|
local public_ip=$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)
|
|
|
|
local public_ip=$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)
|
|
|
|
|
|
|
|
|
|
|
|
if [[ -n $public_ip ]]; then
|
|
|
|
if [[ -n $public_ip ]]; then
|
|
|
@ -499,12 +501,13 @@ prompt_public_ip() {
|
|
|
|
# Context: user@hostname (who am I and where am I)
|
|
|
|
# Context: user@hostname (who am I and where am I)
|
|
|
|
# Note that if $DEFAULT_USER is not set, this prompt segment will always print
|
|
|
|
# Note that if $DEFAULT_USER is not set, this prompt segment will always print
|
|
|
|
prompt_context() {
|
|
|
|
prompt_context() {
|
|
|
|
|
|
|
|
set_default POWERLEVEL9K_CONTEXT_HOST_DEPTH "%m"
|
|
|
|
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
|
|
|
|
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
|
|
|
|
if [[ $(print -P "%#") == '#' ]]; then
|
|
|
|
if [[ $(print -P "%#") == '#' ]]; then
|
|
|
|
# Shell runs as root
|
|
|
|
# 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
|
|
|
|
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
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|