Update pwd test

This commit is contained in:
Ilan Cosman 2020-07-10 19:25:02 -07:00
parent bb129150f8
commit 69356d4a15
2 changed files with 36 additions and 25 deletions

View File

@ -4,10 +4,8 @@ function _tide_pwd
set -g _tide_pwd_output $colorDirs$_tide_pwd
if not test -w $PWD
if test -n "$tide_pwd_unwritable_icon"
set _tide_pwd_output "$tide_pwd_unwritable_icon "$_tide_pwd_output
end
if not test -w $PWD -a -n "$tide_pwd_unwritable_icon"
set _tide_pwd_output "$colorDirs$tide_pwd_unwritable_icon "$_tide_pwd_output
end
set -l truncatedList '.' $_tide_split_pwd
@ -15,19 +13,17 @@ function _tide_pwd
for dir in $_tide_split_pwd
if contains $dir $_tide_pwd_anchors
set _tide_pwd_output (string replace $dir (set_color -o $tide_pwd_color_anchors)$dir(set_color normal -b $tide_pwd_bg_color) $_tide_pwd_output)
else
if test (string length $truncatedPwd) -gt $_tide_pwd_max_length
set -l dirTruncated $dir
set -l truncationLength 1
while contains $dirTruncated $truncatedList
set dirTruncated (string sub -l $truncationLength $dir)
set truncationLength (math $truncationLength+1)
end
set -a truncatedList $dirTruncated
set truncatedPwd (string replace $dir $dirTruncated $truncatedPwd)
set _tide_pwd_output (string replace $dir (set_color $tide_pwd_color_truncated_dirs)$dirTruncated $_tide_pwd_output)
else if test (string length $truncatedPwd) -gt $_tide_pwd_max_length
set -l dirTruncated $dir
set -l truncationLength 1
while contains $dirTruncated $truncatedList
set dirTruncated (string sub -l $truncationLength $dir)
set truncationLength (math $truncationLength+1)
end
set -a truncatedList $dirTruncated
set truncatedPwd (string replace $dir $dirTruncated $truncatedPwd)
set _tide_pwd_output (string replace $dir (set_color $tide_pwd_color_truncated_dirs)$dirTruncated $_tide_pwd_output)
end
end

View File

@ -5,18 +5,33 @@ function _pwd -a dir
_tide_decolor (_tide_item_pwd)
end
# Unwritable directories
sudo mkdir -p /unwritable/dir
set -l unwr "$tide_pwd_unwritable_icon "
@test '/' (_pwd '/') = $unwr'/'
@test '/usr' (_pwd '/usr') = $unwr'/usr'
@test '/usr/share' (_pwd '/usr/share') = $unwr'/usr/share'
@test '~' (_pwd "$HOME") = '~'
@test '~/.config' (_pwd "$HOME/.config") = '~/.config'
@test '~/.config/fish' (_pwd "$HOME/.config/fish") = '~/.config/fish'
@test '/unwritable' (_pwd '/unwritable') = $unwr'/unwritable'
@test '/unwritable/dir' (_pwd '/unwritable/dir') = $unwr'/unwritable/dir'
sudo rm -rf /unwritable
# Normal directories
mkdir -p ~/normal/dir
@test '~' (_pwd ~) = '~'
@test '~/normal' (_pwd ~/normal) = '~/normal'
@test '~/normal/dir' (_pwd ~/normal/dir) = '~/normal/dir'
rm -rf ~/normal
# Long directories
set -l longDir "$HOME/alfa/bravo/charlie/delta/echo/foxtrot/golf/hotel/inda/juliett/kilo/lima/mike/november/oscar/papa"
if not test -e $longDir
mkdir -p $longDir
end
mkdir -p $longDir
@test 'Long dir' (_pwd "$longDir") = '~/a/b/c/d/e/f/g/hotel/inda/juliett/kilo/lima/mike/november/oscar/papa'
rm -r $longDir
rm -r ~/alfa