Refactor absolute char truncation

pull/22/head
Daniel Tam 7 years ago
parent 04850df750
commit eb1c6ec1fc
No known key found for this signature in database
GPG Key ID: 28DC329F2B6F7A6B

@ -730,10 +730,8 @@ prompt_dir() {
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
truncate_absolute_chars) truncate_absolute_chars)
if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then if [ ${#current_path} -gt $(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} )) ]; then
current_path=$(echo $current_path | rev | cut -c 1-$POWERLEVEL9K_SHORTEN_DIR_LENGTH | rev | cat <(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) -) current_path=$POWERLEVEL9K_SHORTEN_DELIMITER${current_path:(-POWERLEVEL9K_SHORTEN_DIR_LENGTH)}
fi fi
# Alternative implementation
#current_path="%$POWERLEVEL9K_SHORTEN_DIR_LENGTH<$POWERLEVEL9K_SHORTEN_DELIMITER<%~%<<"
;; ;;
truncate_middle) truncate_middle)
current_path=$(echo "$current_path" | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g") current_path=$(echo "$current_path" | sed $SED_EXTENDED_REGEX_PARAMETER "s/([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})[^/]+([^/]{$POWERLEVEL9K_SHORTEN_DIR_LENGTH})\//\1$POWERLEVEL9K_SHORTEN_DELIMITER\2\//g")

Loading…
Cancel
Save