aboutsummaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorDominik Ritter <dritter03@googlemail.com>2017-01-21 16:30:19 +0300
committerDominik Ritter <dritter03@googlemail.com>2017-01-24 22:34:11 +0300
commitbcb0fed873221588bfd5ba101588d7f646c54ca0 (patch)
tree3a1360f6a477a40b5378ae6abff32b87562021f7 /powerlevel9k.zsh-theme
parenta58e8bdc8cf4c51c80dc9e63eef52e95214c54f2 (diff)
Avoid error if CLOBBER is not set
If the tempfile already exists and CLOBBER is not set, a file exists error occurrs. This commit avoids this problem.
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme12
1 files changed, 11 insertions, 1 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index f104b789..0df17de0 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -469,6 +469,11 @@ prompt_battery() {
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() {
# set default values for segment
set_default POWERLEVEL9K_PUBLIC_IP_TIMEOUT "300"
@@ -531,12 +536,17 @@ prompt_public_ip() {
fi
# 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
# read public IP saved to tmp file
local public_ip=$(cat $POWERLEVEL9K_PUBLIC_IP_FILE)
+ # Draw the prompt segment
if [[ -n $public_ip ]]; then
$1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" 'PUBLIC_IP_ICON'
fi