mirror of
https://github.com/romkatv/powerlevel10k.git
synced 2024-11-16 17:50:09 +00:00
Added edge case tests for ~ and /
Fixed edge cases
This commit is contained in:
parent
64cbdaf4c2
commit
110f54f7e2
1 changed files with 43 additions and 34 deletions
|
@ -723,8 +723,9 @@ set_default POWERLEVEL9K_DIR_PATH_HIGHLIGHT_BOLD false
|
||||||
# * $1 Alignment: string - left|right
|
# * $1 Alignment: string - left|right
|
||||||
# * $2 Index: integer
|
# * $2 Index: integer
|
||||||
prompt_dir() {
|
prompt_dir() {
|
||||||
local current_path="$(print -P "%~")"
|
local current_dir="$(print -P "%~")"
|
||||||
local paths=(${(s:/:)PWD})
|
local paths
|
||||||
|
[[ current_dir != "/" ]] && paths=(${(s:/:)current_dir}) || paths[0] = "/"
|
||||||
local cur_path cur_short_path directory dir_length cur_dir
|
local cur_path cur_short_path directory dir_length cur_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
|
||||||
|
@ -732,7 +733,8 @@ prompt_dir() {
|
||||||
|
|
||||||
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
|
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
|
||||||
truncate_middle)
|
truncate_middle)
|
||||||
cur_short_path='/'
|
if [[ $current_dir != "/" ]]; then
|
||||||
|
[[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/'
|
||||||
local last_pos
|
local last_pos
|
||||||
local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 ))
|
local max_length=$(( $POWERLEVEL9K_SHORTEN_DIR_LENGTH * 2 ))
|
||||||
for directory in ${paths[@]}
|
for directory in ${paths[@]}
|
||||||
|
@ -746,9 +748,13 @@ prompt_dir() {
|
||||||
cur_short_path+="$cur_dir/"
|
cur_short_path+="$cur_dir/"
|
||||||
done
|
done
|
||||||
current_path="${cur_short_path: : -1}"
|
current_path="${cur_short_path: : -1}"
|
||||||
|
else
|
||||||
|
current_path="/"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
truncate_from_right)
|
truncate_from_right)
|
||||||
cur_short_path='/'
|
if [[ $current_dir != "/" ]]; then
|
||||||
|
[[ $current_dir == '~'* ]] && cur_short_path='' || cur_short_path='/'
|
||||||
for directory in ${paths[@]}
|
for directory in ${paths[@]}
|
||||||
do
|
do
|
||||||
cur_dir=$directory
|
cur_dir=$directory
|
||||||
|
@ -758,6 +764,9 @@ prompt_dir() {
|
||||||
cur_short_path+="$cur_dir/"
|
cur_short_path+="$cur_dir/"
|
||||||
done
|
done
|
||||||
current_path="${cur_short_path: : -1}"
|
current_path="${cur_short_path: : -1}"
|
||||||
|
else
|
||||||
|
current_path="/"
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
truncate_with_package_name)
|
truncate_with_package_name)
|
||||||
local name repo_path package_path current_dir zero
|
local name repo_path package_path current_dir zero
|
||||||
|
@ -769,11 +778,11 @@ prompt_dir() {
|
||||||
# Remove trailing slash from git path, so that we can
|
# Remove trailing slash from git path, so that we can
|
||||||
# remove that git path from the pwd.
|
# remove that git path from the pwd.
|
||||||
gitPath=${gitPath%/}
|
gitPath=${gitPath%/}
|
||||||
package_path=${$current_path%%$gitPath}
|
package_path=${current_dir%%$gitPath}
|
||||||
# Remove trailing slash
|
# Remove trailing slash
|
||||||
package_path=${package_path%/}
|
package_path=${package_dir%/}
|
||||||
elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then
|
elif [[ $(git rev-parse --is-inside-git-dir 2> /dev/null) == "true" ]]; then
|
||||||
package_path=${$current_path%%/.git*}
|
package_path=${current_dir%%/.git*}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Replace the shortest possible match of the marked folder from
|
# Replace the shortest possible match of the marked folder from
|
||||||
|
@ -785,7 +794,7 @@ prompt_dir() {
|
||||||
# Then, find the length of the package_path string, and save the
|
# Then, find the length of the package_path string, and save the
|
||||||
# subdirectory path as a substring of the current directory's path from 0
|
# subdirectory path as a substring of the current directory's path from 0
|
||||||
# to the length of the package path's string
|
# to the length of the package path's string
|
||||||
subdirectory_path=$(truncatePathFromRight "${current_path:${#${(S%%)package_path//$~zero/}}}")
|
subdirectory_path=$(truncatePathFromRight "${current_dir:${#${(S%%)package_path//$~zero/}}}")
|
||||||
# Parse the 'name' from the package.json; if there are any problems, just
|
# Parse the 'name' from the package.json; if there are any problems, just
|
||||||
# print the file path
|
# print the file path
|
||||||
defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)
|
defined POWERLEVEL9K_DIR_PACKAGE_FILES || POWERLEVEL9K_DIR_PACKAGE_FILES=(package.json composer.json)
|
||||||
|
@ -807,7 +816,7 @@ prompt_dir() {
|
||||||
# from the package.json and append the current subdirectory
|
# from the package.json and append the current subdirectory
|
||||||
current_path="`echo $packageName | tr -d '"'`$subdirectory_path"
|
current_path="`echo $packageName | tr -d '"'`$subdirectory_path"
|
||||||
else
|
else
|
||||||
current_path=$(truncatePathFromRight "$(pwd | sed -e "s,^$HOME,~,")" )
|
current_path=$(truncatePathFromRight ${current_path//$HOME/"~"} )
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
truncate_with_folder_marker)
|
truncate_with_folder_marker)
|
||||||
|
@ -834,7 +843,7 @@ prompt_dir() {
|
||||||
|
|
||||||
# Replace the shortest possible match of the marked folder from
|
# Replace the shortest possible match of the marked folder from
|
||||||
# the current path.
|
# the current path.
|
||||||
current_path=$current_path${PWD#${last_marked_folder}*}
|
current_path=$current_path${current_dir#${last_marked_folder}*}
|
||||||
;;
|
;;
|
||||||
truncate_to_unique)
|
truncate_to_unique)
|
||||||
# for each parent path component find the shortest unique beginning
|
# for each parent path component find the shortest unique beginning
|
||||||
|
@ -878,9 +887,9 @@ prompt_dir() {
|
||||||
local current_state="DEFAULT"
|
local current_state="DEFAULT"
|
||||||
if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then
|
if [[ "${POWERLEVEL9K_DIR_SHOW_WRITABLE}" == true && ! -w "$PWD" ]]; then
|
||||||
current_state="NOT_WRITABLE"
|
current_state="NOT_WRITABLE"
|
||||||
elif [[ $(print -P "%~") == '~' ]]; then
|
elif [[ $current_dir == '~' ]]; then
|
||||||
current_state="HOME"
|
current_state="HOME"
|
||||||
elif [[ $(print -P "%~") == '~'* ]]; then
|
elif [[ $current_dir == '~'* ]]; then
|
||||||
current_state="HOME_SUBFOLDER"
|
current_state="HOME_SUBFOLDER"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue