1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-23 15:41:57 +00:00

Fix issue with SHORTEN_DELIM

If `$POWERLEVEL9K_SHORTEN_DELIMITER` is a unicode escape sequence, its
length is 6 instead of 1. Added variable to hold actual character(s)
This commit is contained in:
Christo Kotze 2018-02-17 21:09:27 +04:00
parent 728aa0ec38
commit 9a3dd6bf25

View file

@ -730,6 +730,7 @@ prompt_dir() {
if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" || "$POWERLEVEL9K_SHORTEN_STRATEGY" == "truncate_with_folder_marker" ]]; then
set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026' set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\u2026'
local delim=$(echo -n $POWERLEVEL9K_SHORTEN_DELIMITER) # convert delimiter from unicode to literal character if required
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
truncate_middle) truncate_middle)
@ -743,7 +744,7 @@ prompt_dir() {
dir_length=${#cur_dir} dir_length=${#cur_dir}
if (( $dir_length > $max_length )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path if (( $dir_length > $max_length )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path
last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH )) last_pos=$(( $dir_length - $POWERLEVEL9K_SHORTEN_DIR_LENGTH ))
cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER${cur_dir:$last_pos:$dir_length} cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim${cur_dir:$last_pos:$dir_length}
fi fi
cur_short_path+="$cur_dir/" cur_short_path+="$cur_dir/"
done done
@ -758,8 +759,10 @@ prompt_dir() {
for directory in ${paths[@]} for directory in ${paths[@]}
do do
cur_dir=$directory cur_dir=$directory
if (( ${#cur_dir} > ( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#POWERLEVEL9K_SHORTEN_DELIMITER} ) )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path dir_length=${#cur_dir}
cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$POWERLEVEL9K_SHORTEN_DELIMITER local threshhold=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH + ${#delim} ))
if (( $dir_length > $threshhold )) && [[ $cur_dir != $paths[${#paths}] ]]; then # only shorten if long enough and not last path
cur_dir=${cur_dir:0:$POWERLEVEL9K_SHORTEN_DIR_LENGTH}$delim
fi fi
cur_short_path+="$cur_dir/" cur_short_path+="$cur_dir/"
done done