diff options
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | powerlevel9k.zsh-theme | 63 |
2 files changed, 64 insertions, 11 deletions
@@ -278,6 +278,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 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 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 +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 4773ac59..3b75671d 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -186,19 +186,49 @@ case $POWERLEVEL9K_MODE in ;; esac +if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then + VCS_BRANCH_ICON='' +fi + # 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='' ;; + 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 -if [[ "$POWERLEVEL9K_HIDE_BRANCH_ICON" == true ]]; then - VCS_BRANCH_ICON='' +# 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 ################################################################ @@ -482,8 +512,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 + truncate_middle) + 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 $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+\//\1..\//g") + ;; + *) + current_path="%$((POWERLEVEL9K_SHORTEN_DIR_LENGTH+1))(c:.../:)%${POWERLEVEL9K_SHORTEN_DIR_LENGTH}c" + ;; + esac + fi $1_prompt_segment "$0" "blue" "$DEFAULT_COLOR" "$current_path" |