aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Averty <benoit.averty@gmail.com>2016-08-10 01:07:04 +0300
committerDominik Ritter <dritter03@googlemail.com>2017-02-01 01:47:49 +0300
commitebf808c533ed86ede4b5afcf9206c05b832278db (patch)
tree9a74b5cdb088183077229a7941a796d06118c718
parenta58e8bdc8cf4c51c80dc9e63eef52e95214c54f2 (diff)
Add dir_truncate_root option
-rw-r--r--functions/utilities.zsh15
-rwxr-xr-xpowerlevel9k.zsh-theme17
2 files changed, 30 insertions, 2 deletions
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"
;;