mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-11 08:00:06 +00:00
Merge pull request #386 from dritter/fix_public_ip
Avoid error if CLOBBER is not set in public_ip segment.
This commit is contained in:
commit
ddcbc62a05
1 changed files with 11 additions and 1 deletions
|
@ -469,6 +469,11 @@ prompt_battery() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Public IP segment
|
||||||
|
# Parameters:
|
||||||
|
# * $1 Alignment: string - left|right
|
||||||
|
# * $2 Index: integer
|
||||||
|
# * $3 Joined: bool - If the segment should be joined
|
||||||
prompt_public_ip() {
|
prompt_public_ip() {
|
||||||
# set default values for segment
|
# set default values for segment
|
||||||
set_default POWERLEVEL9K_PUBLIC_IP_TIMEOUT "300"
|
set_default POWERLEVEL9K_PUBLIC_IP_TIMEOUT "300"
|
||||||
|
@ -531,12 +536,17 @@ prompt_public_ip() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# write IP to tmp file or clear tmp file if an IP was not retrieved
|
# 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
|
# Redirection with `>!`. From the manpage: Same as >, except that the file
|
||||||
|
# is truncated to zero length if it exists, even if CLOBBER is unset.
|
||||||
|
# If the file already exists, and a simple `>` redirection and CLOBBER
|
||||||
|
# unset, ZSH will produce an error.
|
||||||
|
[[ -n "${fresh_ip}" ]] && echo $fresh_ip >! $POWERLEVEL9K_PUBLIC_IP_FILE || echo $POWERLEVEL9K_PUBLIC_IP_NONE >! $POWERLEVEL9K_PUBLIC_IP_FILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# read public IP saved 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)
|
||||||
|
|
||||||
|
# Draw the prompt segment
|
||||||
if [[ -n $public_ip ]]; then
|
if [[ -n $public_ip ]]; then
|
||||||
$1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" 'PUBLIC_IP_ICON'
|
$1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" 'PUBLIC_IP_ICON'
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue