Also eval _tide_pwd

This commit is contained in:
Ilan Cosman 2022-01-05 11:25:32 -08:00
parent fc17a69914
commit ea0b386a0c
3 changed files with 40 additions and 46 deletions

View File

@ -1,30 +1,9 @@
function _tide_cache_variables
# pwd
set -l data (
# pwd
set_color -o $tide_pwd_color_anchors
echo
set_color $tide_pwd_color_truncated_dirs
echo
set_color normal -b $tide_pwd_bg_color; set_color $tide_pwd_color_dirs
echo
# Same-color-separator color
set_color $tide_prompt_color_separator_same_color
echo
# git
set_color $tide_git_color_branch
)
# pwd
set -g _tide_color_anchors "$data[1]"
set -g _tide_color_truncated_dirs "$data[2]"
set -g _tide_reset_to_color_dirs "$data[3]"
# Same-color-separator color
set -gx _tide_color_separator_same_color "$data[4]"
set_color $tide_prompt_color_separator_same_color | read -gx _tide_color_separator_same_color
# git
contains git $_tide_left_items $_tide_right_items && set -gx _tide_location_color "$data[5]"
contains git $_tide_left_items $_tide_right_items && set_color $tide_git_color_branch | read -gx _tide_location_color
# private_mode
if contains private_mode $_tide_left_items $_tide_right_items && test -n "$fish_private_mode"

View File

@ -1,39 +1,53 @@
function _tide_pwd
set -l split_pwd (string replace -- $HOME '~' $PWD | string split /)
set -l data (
set_color -o $tide_pwd_color_anchors
echo
set_color $tide_pwd_color_truncated_dirs
echo
set_color normal -b $tide_pwd_bg_color; set_color $tide_pwd_color_dirs)
set -l _tide_color_anchors "$data[1]"
set -l _tide_color_truncated_dirs "$data[2]"
set -l _tide_reset_to_color_dirs "$data[3]"
if not test -w $PWD
set -f icon $tide_pwd_icon_unwritable' '
else if test $PWD = $HOME
set -f icon $tide_pwd_icon_home' '
set -l unwritable_icon $tide_pwd_icon_unwritable'\ '
set -l home_icon $tide_pwd_icon_home'\ '
set -l pwd_icon $tide_pwd_icon'\ '
eval "function _tide_pwd
set -l split_pwd (string replace -- $HOME '~' \$PWD | string split /)
if not test -w \$PWD
set -f icon $unwritable_icon
else if test \$PWD = $HOME
set -f icon $home_icon
else
set -f icon $tide_pwd_icon' '
set -f icon $pwd_icon
end
# Anchor first and last directories (which may be the same)
test -n "$split_pwd[1]" && # ~/foo/bar, hightlight ~ OR /foo/bar, hightlight foo not empty string
set -l split_output "$_tide_reset_to_color_dirs$icon"$_tide_color_anchors$split_pwd[1]$_tide_reset_to_color_dirs $split_pwd[2..] ||
set -l split_output "$_tide_reset_to_color_dirs$icon" $_tide_color_anchors$split_pwd[2]$_tide_reset_to_color_dirs $split_pwd[3..]
set split_output[-1] $_tide_color_anchors$split_pwd[-1]$_tide_reset_to_color_dirs
test -n \"\$split_pwd[1]\" && # ~/foo/bar, hightlight ~ OR /foo/bar, hightlight foo not empty string
set -l split_output \"$_tide_reset_to_color_dirs\$icon$_tide_color_anchors\$split_pwd[1]$_tide_reset_to_color_dirs\" \$split_pwd[2..] ||
set -l split_output \"$_tide_reset_to_color_dirs\$icon\" \"$_tide_color_anchors\$split_pwd[2]$_tide_reset_to_color_dirs\" \$split_pwd[3..]
set split_output[-1] \"$_tide_color_anchors\$split_pwd[-1]$_tide_reset_to_color_dirs\"
string join / $split_output | string length --visible | read -g pwd_length
string join / \$split_output | string length --visible | read -g pwd_length
i=1 for dir_section in $split_pwd[2..-2]
string join -- / $split_pwd[..$i] | string replace '~' $HOME | read -l parent_dir # Uses i before increment
i=1 for dir_section in \$split_pwd[2..-2]
string join -- / \$split_pwd[..\$i] | string replace '~' $HOME | read -l parent_dir # Uses i before increment
math $i+1 | read i
math \$i+1 | read i
if false || for marker in $tide_pwd_markers # false is for if tide_pwd_markers is empty
test -e $parent_dir/$dir_section/$marker && break
test -e \$parent_dir/\$dir_section/\$marker && break
end
set split_output[$i] $_tide_color_anchors$dir_section$_tide_reset_to_color_dirs
else if test $pwd_length -gt $dist_btwn_sides
set split_output[\$i] \"$_tide_color_anchors\$dir_section$_tide_reset_to_color_dirs\"
else if test \$pwd_length -gt \$dist_btwn_sides
set -l trunc
while string match -qr "(?<trunc>$trunc.)" $dir_section && test (count $parent_dir/$trunc*/) != 1
while string match -qr \"(?<trunc>\$trunc.)\" \$dir_section && test (count \$parent_dir/\$trunc*/) != 1
end
test -n "$trunc" && set split_output[$i] $_tide_color_truncated_dirs$trunc$_tide_reset_to_color_dirs &&
string join / $split_output | string length --visible | read -g pwd_length
test -n \"\$trunc\" && set split_output[\$i] \"$_tide_color_truncated_dirs\$trunc$_tide_reset_to_color_dirs\" &&
string join / \$split_output | string length --visible | read -g pwd_length
end
end
string join -- / $split_output
end
string join -- / \$split_output
end"

View File

@ -5,6 +5,7 @@ status is-interactive || exit
_tide_remove_unusable_items
_tide_cache_variables
source (functions --details _tide_pwd)
# The first element in $$_tide_prompt_var is right prompt
# All remaining ones are 'left' prompt (also upper right in 2-line prompts)