From 2bc3b09963f34e3f404556100f28b4bf4e904a92 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 25 Jul 2015 01:34:11 +0200 Subject: [PATCH 1/6] Implemented different ways to truncate the directory path. --- README.md | 12 ++++++++++++ powerlevel9k.zsh-theme | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 71dfceb2..4aec6745 100644 --- a/README.md +++ b/README.md @@ -272,6 +272,18 @@ to a certain length: # Limit to the last two folders POWERLEVEL9K_SHORTEN_DIR_LENGTH=2 +To change the way how the current working directory is truncated, just set: + + # truncate whole directories + POWERLEVEL9K_SHORTEN_STRATEGY="complete_directories" + # truncate from right, leaving the first X characters untouched + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" + # default behaviour is to truncate the middle part of the directory + +In each case you have to specify the length you want to shorten the directory +to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in +others whole directories. + #### The 'time' segment By default the time is show in 'H:M:S' format. If you want to change it, diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 69eee6e3..3e793d7e 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -450,8 +450,19 @@ prompt_context() { prompt_dir() { local current_path='%~' if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then - # shorten path to $POWERLEVEL9K_SHORTEN_DIR_LENGTH - current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + + case "$POWERLEVEL9K_SHORTEN_STRATEGY" in + complete_directories) + current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + ;; + truncate_from_right) + current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1\//g") + ;; + *) + current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g") + ;; + esac + fi $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$current_path" From 99504d4ad44ea88af8ec6f84c8c38415044e7557 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 29 Jul 2015 23:46:06 +0200 Subject: [PATCH 2/6] Add an indicator that directories were truncated. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 3e793d7e..da3e617b 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -456,7 +456,7 @@ prompt_dir() { current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; truncate_from_right) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1\//g") + current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g") ;; *) current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g") From 754b648f372924214a32a09205cc4aca7f93af12 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 5 Aug 2015 00:21:09 +0200 Subject: [PATCH 3/6] Changed the default behaviour to truncate whole directories. --- README.md | 6 +++--- powerlevel9k.zsh-theme | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 787e98f6..0b130120 100644 --- a/README.md +++ b/README.md @@ -279,11 +279,11 @@ to a certain length: To change the way how the current working directory is truncated, just set: - # truncate whole directories - POWERLEVEL9K_SHORTEN_STRATEGY="complete_directories" + # truncate the middle part + POWERLEVEL9K_SHORTEN_STRATEGY="truncate_middle" # truncate from right, leaving the first X characters untouched POWERLEVEL9K_SHORTEN_STRATEGY="truncate_from_right" - # default behaviour is to truncate the middle part of the directory + # default behaviour is to truncate whole directories In each case you have to specify the length you want to shorten the directory to. So in some cases `POWERLEVEL9K_SHORTEN_DIR_LENGTH` means characters, in diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 4ee919cc..7ce0a5f9 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -484,14 +484,14 @@ prompt_dir() { if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then case "$POWERLEVEL9K_SHORTEN_STRATEGY" in - complete_directories) - current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + truncate_middle) + current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g") ;; truncate_from_right) current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g") ;; *) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g") + current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" ;; esac From 44db352e3512ff73f071e592868044d8ca8c5447 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Sat, 15 Aug 2015 15:49:22 +0200 Subject: [PATCH 4/6] Issue #64: Now the theme detects on OSX which sed is to use. --- powerlevel9k.zsh-theme | 56 ++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7ce0a5f9..fffc470e 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -186,21 +186,51 @@ case $POWERLEVEL9K_MODE in ;; esac -# OS detection for the `os_icon` segment -case $(uname) in - Darwin) OS_ICON=$APPLE_ICON ;; - FreeBSD) OS_ICON=$FREEBSD_ICON ;; - OpenBSD) OS_ICON=$FREEBSD_ICON ;; - DragonFly) OS_ICON=$FREEBSD_ICON ;; - Linux) OS_ICON=$LINUX_ICON ;; - SunOS) OS_ICON=$SUNOS_ICON ;; - *) OS_ICON='' ;; -esac - if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then VCS_BRANCH_ICON='' fi +# OS detection for the `os_icon` segment +case $(uname) in + Darwin) + OS='OSX' + OS_ICON=$APPLE_ICON + ;; + FreeBSD) + OS='BSD' + OS_ICON=$FREEBSD_ICON + ;; + OpenBSD) + OS='BSD' + OS_ICON=$FREEBSD_ICON + ;; + DragonFly) + OS='BSD' + OS_ICON=$FREEBSD_ICON + ;; + Linux) + OS='Linux' + OS_ICON=$LINUX_ICON + ;; + SunOS) + OS='Solaris' + OS_ICON=$SUNOS_ICON + ;; + *) + OS='' + OS_ICON='' + ;; +esac + +# Determine the correct sed parameter. +SED_EXTENDED_REGEX_PARAMETER="-r" +if [[ "$OS" == 'OSX' ]]; then + local IS_BSD_SED=$(sed --version &>> /dev/null || echo "BSD sed") + if [[ -n "$IS_BSD_SED" ]]; then + SED_EXTENDED_REGEX_PARAMETER="-E" + fi +fi + ################################################################ # color scheme ################################################################ @@ -485,10 +515,10 @@ prompt_dir() { case "$POWERLEVEL9K_SHORTEN_STRATEGY" in truncate_middle) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g") + current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1\.\.\2\//g") ;; truncate_from_right) - current_path=$(pwd | sed -e "s,^$HOME,~," | sed -E "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g") + current_path=$(pwd | sed -e "s,^$HOME,~," | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g") ;; *) current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" From b443c9be4a718a0b2d59902eb162c3906ee38735 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 17:24:23 +0200 Subject: [PATCH 5/6] Moved `print_icon` to top in its own section "utility functions". --- powerlevel9k.zsh-theme | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index ae9da42a..b7b7858f 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -44,6 +44,21 @@ #zstyle ':vcs_info:*+*:*' debug true #set -o xtrace +################################################################ +# Utility functions +################################################################ + +function print_icon() { + local icon_name=$1 + local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} + local USER_ICON=${(P)ICON_USER_VARIABLE} + if [[ -n "$USER_ICON" ]]; then + echo -n $USER_ICON + else + echo -n ${icons[$icon_name]} + fi +} + ################################################################ # Icons ################################################################ @@ -190,17 +205,6 @@ if [[ "$OS" == 'OSX' ]]; then fi fi -function print_icon() { - local icon_name=$1 - local ICON_USER_VARIABLE=POWERLEVEL9K_${icon_name} - local USER_ICON=${(P)ICON_USER_VARIABLE} - if [[ -n "$USER_ICON" ]]; then - echo -n $USER_ICON - else - echo -n ${icons[$icon_name]} - fi -} - ################################################################ # color scheme ################################################################ From 7535f62746c9d172d14adfe437a8573e682a12da Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 26 Aug 2015 17:35:25 +0200 Subject: [PATCH 6/6] Added a new Icon to the dir-segment. --- powerlevel9k.zsh-theme | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index b7b7858f..56ecb611 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -90,6 +90,7 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON $'\U1F608 ' # 😈 LINUX_ICON $'\U1F427 ' # 🐧 SUNOS_ICON $'\U1F31E ' # 🌞 + HOME_ICON $'\UE12C' #  VCS_UNTRACKED_ICON "\UE16C" #  VCS_UNSTAGED_ICON "\UE17C" #  VCS_STAGED_ICON "\UE168" #  @@ -130,6 +131,7 @@ case $POWERLEVEL9K_MODE in FREEBSD_ICON 'BSD' LINUX_ICON 'Lx' SUNOS_ICON 'Sun' + HOME_ICON '' VCS_UNTRACKED_ICON '?' VCS_UNSTAGED_ICON "\u25CF" # ● VCS_STAGED_ICON "\u271A" # ✚ @@ -506,7 +508,7 @@ prompt_dir() { fi - $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$current_path" + $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$(print_icon 'HOME_ICON') $current_path" } # Command number (in local history)