From bcb0fed873221588bfd5ba101588d7f646c54ca0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 21 Jan 2017 14:30:19 +0100 Subject: 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. --- powerlevel9k.zsh-theme | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') 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 -- cgit v1.2.3 From a576a157599ef3b41b939c4e8dc5df8656c30023 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 25 Jan 2017 23:47:20 +0100 Subject: Fix error with truncating package name if repo is symlinked --- powerlevel9k.zsh-theme | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f104b789..38c2ceb4 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -587,7 +587,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 -- cgit v1.2.3 From 6c352c8d5c90c189166beb07e3f9f7c753f6b79d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Jan 2017 01:29:38 +0100 Subject: Simplify `public_ip` segment --- powerlevel9k.zsh-theme | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f104b789..f1e4314b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -475,6 +475,7 @@ prompt_public_ip() { 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" + defined POWERLEVEL9K_PUBLIC_IP_METHODS || POWERLEVEL9K_PUBLIC_IP_METHODS=(wget curl dig) # Do we need a fresh IP? local refresh_ip=false @@ -491,51 +492,33 @@ prompt_public_ip() { fi # grab a fresh IP if needed + local fresh_ip if [[ $refresh_ip =~ true && -w $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then - # if method specified, don't use fallback methods - if [[ -n $POWERLEVEL9K_PUBLIC_IP_METHOD ]] && [[ $POWERLEVEL9K_PUBLIC_IP_METHOD =~ 'wget|curl|dig' ]]; then - local method=$POWERLEVEL9K_PUBLIC_IP_METHOD - fi - if [[ -n $method ]]; then + for method in "${POWERLEVEL9K_PUBLIC_IP_METHODS[@]}"; do case $method in 'dig') - if type -p dig >/dev/null; then - fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)" - [[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip - fi + fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)" + [[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip ;; 'curl') - if [[ -z "$fresh_ip" ]] && type -p curl >/dev/null; then - fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" - fi + fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" ;; 'wget') - if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then - fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" - fi + fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" ;; esac - else - if type -p dig >/dev/null; then - fresh_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com 2> /dev/null)" - [[ "$fresh_ip" =~ ^\; ]] && unset fresh_ip - fi - - if [[ -z "$fresh_ip" ]] && type -p curl >/dev/null; then - fresh_ip="$(curl --max-time 10 -w '\n' "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" + # If we found a fresh IP, break loop. + if [[ -n "${fresh_ip}" ]]; then + break; fi - - if [[ -z "$fresh_ip" ]] && type -p wget >/dev/null; then - fresh_ip="$(wget -T 10 -qO- "$POWERLEVEL9K_PUBLIC_IP_HOST" 2> /dev/null)" - fi - fi + 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 fi # 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 $1_prompt_segment "$0" "$2" "$DEFAULT_COLOR" "$DEFAULT_COLOR_INVERTED" "${public_ip}" 'PUBLIC_IP_ICON' -- cgit v1.2.3 From 06cb9bb43fd6a5010fafa116fabe8290f87a90f0 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 28 Jan 2017 13:21:40 +0100 Subject: Change order of public ip methods as it was before --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f1e4314b..61d9f99c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -475,7 +475,7 @@ prompt_public_ip() { 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" - defined POWERLEVEL9K_PUBLIC_IP_METHODS || POWERLEVEL9K_PUBLIC_IP_METHODS=(wget curl dig) + defined POWERLEVEL9K_PUBLIC_IP_METHODS || POWERLEVEL9K_PUBLIC_IP_METHODS=(dig curl wget) # Do we need a fresh IP? local refresh_ip=false -- cgit v1.2.3 From ebf808c533ed86ede4b5afcf9206c05b832278db Mon Sep 17 00:00:00 2001 From: Benoit Averty Date: Wed, 10 Aug 2016 00:07:04 +0200 Subject: Add dir_truncate_root option --- functions/utilities.zsh | 15 +++++++++++++++ powerlevel9k.zsh-theme | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/utilities.zsh b/functions/utilities.zsh index f27c7f99..8263ce10 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -208,3 +208,18 @@ function truncatePathFromRight() { echo $1 | sed $SED_EXTENDED_REGEX_PARAMETER \ "s@(([^/]{$((POWERLEVEL9K_SHORTEN_DIR_LENGTH))})([^/]{$delim_len}))[^/]+/@\2$POWERLEVEL9K_SHORTEN_DELIMITER/@g" } + +# Search recursively in parent folders for given file. +function upsearch () { + if test -e "$1"; then + echo "$PWD" + else + if [[ "$PWD" == "/" || "$PWD" == "$HOME" ]]; then + echo "$PWD"; + else + pushd .. > /dev/null + upsearch "$1" + popd > /dev/null + fi + fi +} diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f104b789..c679ba56 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -571,8 +571,7 @@ prompt_custom() { set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" prompt_dir() { local current_path='%~' - if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then - + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_root_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' case "$POWERLEVEL9K_SHORTEN_STRATEGY" in @@ -610,6 +609,20 @@ prompt_dir() { current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) fi ;; + truncate_with_root_marker) + local dir_truncate_root + + dir_truncate_root=$(upsearch $POWERLEVEL9K_ROOT_MARKER_FILE) + zero='%([BSUbfksu]|([FB]|){*})' + + if [[ "$dir_truncate_root" == "/" || "$dir_truncate_root" == "$HOME" ]]; then + current_path='%~' + elif [[ "$dir_truncate_root" == "$HOME"* ]]; then + current_path="~/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" + else + current_path="/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" + fi + ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; -- cgit v1.2.3 From 5cc2d51b5829d0ae2eefaa115892da71f6a14d79 Mon Sep 17 00:00:00 2001 From: Benoit Averty Date: Wed, 10 Aug 2016 13:00:52 +0200 Subject: Fix bug when truncate root was set to direct subfolder of home or root --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c679ba56..afc4a6bc 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -615,7 +615,7 @@ prompt_dir() { dir_truncate_root=$(upsearch $POWERLEVEL9K_ROOT_MARKER_FILE) zero='%([BSUbfksu]|([FB]|){*})' - if [[ "$dir_truncate_root" == "/" || "$dir_truncate_root" == "$HOME" ]]; then + if [[ "$dir_truncate_root" == "/" || "$dir_truncate_root" == "$HOME" || "${dir_truncate_root%/*}" == "$HOME" || ${dir_truncate_root%/*} == "/" ]]; then current_path='%~' elif [[ "$dir_truncate_root" == "$HOME"* ]]; then current_path="~/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" -- cgit v1.2.3 From 9f4772f9930c7d56ab04df900ac94456e5a08a22 Mon Sep 17 00:00:00 2001 From: Benoit Averty Date: Wed, 10 Aug 2016 21:31:58 +0200 Subject: More possibilities with truncate folder marker --- functions/utilities.zsh | 17 +++++++++-------- powerlevel9k.zsh-theme | 30 ++++++++++++++++++------------ 2 files changed, 27 insertions(+), 20 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/utilities.zsh b/functions/utilities.zsh index 8263ce10..22b53c6a 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -211,15 +211,16 @@ function truncatePathFromRight() { # Search recursively in parent folders for given file. function upsearch () { - if test -e "$1"; then + if [[ "$PWD" == "$HOME" || "$PWD" == "/" ]]; then + echo "$PWD" + elif test -e "$1"; then + pushd .. > /dev/null + upsearch "$1" + popd > /dev/null echo "$PWD" else - if [[ "$PWD" == "/" || "$PWD" == "$HOME" ]]; then - echo "$PWD"; - else - pushd .. > /dev/null - upsearch "$1" - popd > /dev/null - fi + pushd .. > /dev/null + upsearch "$1" + popd > /dev/null fi } diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index afc4a6bc..420f7d0b 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -571,7 +571,7 @@ prompt_custom() { set_default POWERLEVEL9K_DIR_PATH_SEPARATOR "/" prompt_dir() { local current_path='%~' - if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_root_marker" ]]; then + if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026' case "$POWERLEVEL9K_SHORTEN_STRATEGY" in @@ -609,19 +609,25 @@ prompt_dir() { current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" ) fi ;; - truncate_with_root_marker) - local dir_truncate_root + truncate_with_folder_marker) + local last_marked_folder marked_folder zero + set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" + + for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do + if [[ "$marked_folder" == "/" ]]; then + current_path="/" + elif [[ "$marked_folder" == "$HOME" ]]; then + current_path="~" + elif [[ "${marked_folder%/*}" == $last_marked_folder ]]; then + current_path="${current_path%/}/${marked_folder##*/}" + else + current_path="${current_path%/}/$POWERLEVEL9K_SHORTEN_DELIMITER/${marked_folder##*/}" + fi + last_marked_folder=$marked_folder + done - dir_truncate_root=$(upsearch $POWERLEVEL9K_ROOT_MARKER_FILE) zero='%([BSUbfksu]|([FB]|){*})' - - if [[ "$dir_truncate_root" == "/" || "$dir_truncate_root" == "$HOME" || "${dir_truncate_root%/*}" == "$HOME" || ${dir_truncate_root%/*} == "/" ]]; then - current_path='%~' - elif [[ "$dir_truncate_root" == "$HOME"* ]]; then - current_path="~/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" - else - current_path="/$POWERLEVEL9K_SHORTEN_DELIMITER/${dir_truncate_root##*/}${PWD:${#${(S%%)dir_truncate_root//$~zero/}}}" - fi + current_path=$current_path${PWD:${#${(S%%)last_marked_folder//$~zero/}}} ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" -- cgit v1.2.3 From 6927b0ca94157e2fb9dcd3b12766b4e913d0e44e Mon Sep 17 00:00:00 2001 From: Benoit Averty Date: Tue, 9 Aug 2016 11:22:02 +0200 Subject: Add directory permission prompt segment --- functions/icons.zsh | 3 +++ powerlevel9k.zsh-theme | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/functions/icons.zsh b/functions/icons.zsh index df92d22a..44d99095 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -78,6 +78,7 @@ case $POWERLEVEL9K_MODE in PYTHON_ICON $'\U1F40D' # 🐍 SWIFT_ICON '' PUBLIC_IP_ICON '' + LOCK_ICON $'\UE138' #  ) ;; 'awesome-fontconfig') @@ -138,6 +139,7 @@ case $POWERLEVEL9K_MODE in PYTHON_ICON $'\U1F40D' # 🐍 SWIFT_ICON '' PUBLIC_IP_ICON '' + LOCK_ICON $'\UE138' #  ) ;; *) @@ -198,6 +200,7 @@ case $POWERLEVEL9K_MODE in PYTHON_ICON '' SWIFT_ICON 'Swift' PUBLIC_IP_ICON '' + LOCK_ICON $'\UE0A2' ) ;; esac diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f104b789..620a5f7d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1114,6 +1114,13 @@ prompt_swift_version() { "$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version}" 'SWIFT_ICON' } +# dir_permision: Display information about the user's permission to write in the current directory +prompt_dir_permission() { + if [[ ! -w "$PWD" ]]; then + "$1_prompt_segment" "$0_FORBIDDEN" "$2" "red" "226" "" 'LOCK_ICON' + fi +} + ################################################################ # Prompt processing and drawing ################################################################ @@ -1240,4 +1247,3 @@ prompt_powerlevel9k_setup() { } prompt_powerlevel9k_setup "$@" - -- cgit v1.2.3 From 052eba9c74b2153dbd70eb4ba829f258a596baf2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 31 Jan 2017 23:57:59 +0100 Subject: Rename `dir_permissions` segment to `dir_writable` Additionally: - Add changelog entry - Add documentation --- CHANGELOG.md | 4 ++++ README.md | 1 + powerlevel9k.zsh-theme | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/CHANGELOG.md b/CHANGELOG.md index defc1dd0..5db1f6e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ Added an option to configure the path separator. If you want something else than an ordinary slash, you could set `POWERLEVEL9K_DIR_PATH_SEPARATOR` to whatever you want. +### New segment 'dir_writable' added + +This segment displays a lock icon if your user has no write permissions in the current folder. + ### New segment 'disk_usage' added This segment will show the usage level of your current partition. diff --git a/README.md b/README.md index f7a80a09..8f606f6b 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ The segments that are currently available are: * [`battery`](#battery) - Current battery status. * [`context`](#context) - Your username and host. * [`dir`](#dir) - Your current working directory. +* `dir_writable` - Displays a lock icon, if you do not have write permissions on the current folder. * [`disk_usage`](#disk_usage) - Disk usage of your current partition. * `history` - The command number for the current line. * [`ip`](#ip) - Shows the current IP address. diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 620a5f7d..b89f390c 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -1114,8 +1114,8 @@ prompt_swift_version() { "$1_prompt_segment" "$0" "$2" "magenta" "white" "${swift_version}" 'SWIFT_ICON' } -# dir_permision: Display information about the user's permission to write in the current directory -prompt_dir_permission() { +# dir_writable: Display information about the user's permission to write in the current directory +prompt_dir_writable() { if [[ ! -w "$PWD" ]]; then "$1_prompt_segment" "$0_FORBIDDEN" "$2" "red" "226" "" 'LOCK_ICON' fi -- cgit v1.2.3 From eb865664e4225b94fc01ce1c05f27d1db18e172d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Feb 2017 00:31:04 +0100 Subject: Add comments to the dir segment --- powerlevel9k.zsh-theme | 2 ++ 1 file changed, 2 insertions(+) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 420f7d0b..723954be 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -615,8 +615,10 @@ prompt_dir() { for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do if [[ "$marked_folder" == "/" ]]; then + # If we reached root folder, stop upsearch. current_path="/" elif [[ "$marked_folder" == "$HOME" ]]; then + # If we reached home folder, stop upsearch. current_path="~" elif [[ "${marked_folder%/*}" == $last_marked_folder ]]; then current_path="${current_path%/}/${marked_folder##*/}" -- cgit v1.2.3 From a4cb875615bedc305168c694793616de8d72c1b3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sun, 12 Feb 2017 23:27:16 +0100 Subject: Add documentation about mysterious 'BSUbfksu' pattern --- powerlevel9k.zsh-theme | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index d51ec8f2..e6befc6d 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -591,7 +591,12 @@ prompt_dir() { package_path=${$(pwd)%%/.git*} fi - zero='%([BSUbfksu]|([FB]|){*})' + # Replace the shortest possible match of the marked folder from + # the current path. Remove the amount of characters up to the + # folder marker from the left. Count only the visible characters + # in the path (this is done by the "zero" pattern; see + # http://stackoverflow.com/a/40855342/5586433). + local zero='%([BSUbfksu]|([FB]|){*})' current_dir=$(pwd) # Then, find the length of the package_path string, and save the # subdirectory path as a substring of the current directory's path from 0 @@ -613,6 +618,9 @@ prompt_dir() { local last_marked_folder marked_folder zero set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" + # Search for the folder marker in the parent directories and + # buildup a pattern that is removed from the current path + # later on. for marked_folder in $(upsearch $POWERLEVEL9K_SHORTEN_FOLDER_MARKER); do if [[ "$marked_folder" == "/" ]]; then # If we reached root folder, stop upsearch. @@ -628,7 +636,12 @@ prompt_dir() { last_marked_folder=$marked_folder done - zero='%([BSUbfksu]|([FB]|){*})' + # Replace the shortest possible match of the marked folder from + # the current path. Remove the amount of characters up to the + # folder marker from the left. Count only the visible characters + # in the path (this is done by the "zero" pattern; see + # http://stackoverflow.com/a/40855342/5586433). + local zero='%([BSUbfksu]|([FB]|){*})' current_path=$current_path${PWD:${#${(S%%)last_marked_folder//$~zero/}}} ;; *) -- cgit v1.2.3 From f6c65e3cf7b87a07b7dffb0c3d77a6932241c242 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 13 Feb 2017 00:18:34 +0100 Subject: Get rid of unreadable BSU-pattern Now the current folder in `truncate_with_folder_marker` strategy is truncated by cutting off the found folder from the beginning of $PWD. --- powerlevel9k.zsh-theme | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'powerlevel9k.zsh-theme') diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index e6befc6d..55e33680 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -615,7 +615,7 @@ prompt_dir() { fi ;; truncate_with_folder_marker) - local last_marked_folder marked_folder zero + local last_marked_folder marked_folder set_default POWERLEVEL9K_SHORTEN_FOLDER_MARKER ".shorten_folder_marker" # Search for the folder marker in the parent directories and @@ -637,12 +637,8 @@ prompt_dir() { done # Replace the shortest possible match of the marked folder from - # the current path. Remove the amount of characters up to the - # folder marker from the left. Count only the visible characters - # in the path (this is done by the "zero" pattern; see - # http://stackoverflow.com/a/40855342/5586433). - local zero='%([BSUbfksu]|([FB]|){*})' - current_path=$current_path${PWD:${#${(S%%)last_marked_folder//$~zero/}}} + # the current path. + current_path=$current_path${PWD#${last_marked_folder}*} ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:$POWERLEVEL9K_SHORTEN_DELIMITER/:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" -- cgit v1.2.3