tide/functions/_tide_item_pwd.fish
2020-06-04 22:50:46 -07:00

56 lines
1.8 KiB
Fish

function _tide_item_pwd
set -l pwd (string replace $HOME '~' $PWD)
set -l colorPwd $pwd
set -l splitPwd (string split '/' $pwd)
set -l maxLength (math $COLUMNS-$tide_pwd_truncate_margin)
set -l colorTruncatedDirs (set_color $tide_pwd_color_truncated_dirs)
set -l colorMidDirs (set_color $tide_pwd_color_dirs)
set -l colorEndDirs (set_color -o $tide_pwd_color_anchors)
set -l anchors (_parse_anchors $splitPwd)
if not test -w $PWD
set_color $tide_pwd_color_dirs
printf '%s' {$tide_pwd_unwritable_icon}' '
end
for dir in $splitPwd
set -l index (contains -i $dir $splitPwd)
if contains $index $anchors
set colorPwd (string replace $dir "$colorEndDirs"$dir(set_color normal) $colorPwd)
else
if test (string length $pwd) -gt $maxLength
set -l dirTruncated (string sub -l 1 $dir)
if test $dirTruncated = '.'
set dirTruncated (string sub -l 2 $dir)
end
set pwd (string replace $dir $dirTruncated $pwd)
set -l colorTruncatedDirs (set_color $tide_pwd_color_truncated_dirs)
set -l colorMidDirs (set_color $tide_pwd_color_dirs)
set colorPwd (string replace $dir "$colorTruncatedDirs"$dirTruncated $colorPwd)
end
end
end
set colorPwd (string replace -a '/' "$colorMidDirs"'/' $colorPwd)
printf '%s ' $colorPwd
end
function _parse_anchors
set -l splitGitDir (string replace $HOME '~' $git_dir | string split '/')
set -l anchors
if contains 'first' $tide_pwd_anchors
set -a anchors 1
end
if contains 'last' $tide_pwd_anchors
set -a anchors (count $argv)
end
if contains 'git' $tide_pwd_anchors
set -a anchors (count $splitGitDir)
end
printf '%s\n' $anchors
end