aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xpowerlevel9k.zsh-theme21
1 files changed, 19 insertions, 2 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 61d9f99c..c7220b3d 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"
@@ -514,12 +519,17 @@ prompt_public_ip() {
done
# 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
@@ -570,7 +580,14 @@ prompt_dir() {
# Get the path of the Git repo, which should have the package.json file
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == "true" ]]; then
- package_path=$(git rev-parse --show-toplevel)
+ # Get path from the root of the git repository to the current dir
+ local gitPath=$(git rev-parse --show-prefix)
+ # Remove trailing slash from git path, so that we can
+ # remove that git path from the pwd.
+ gitPath=${gitPath%/}
+ package_path=${$(pwd)%%$gitPath}
+ # Remove trailing slash
+ package_path=${package_path%/}
elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then
package_path=${$(pwd)%%/.git*}
fi