Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions functions/_tide_pwd.fish
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ eval "function _tide_pwd
if path is \$parent_dir/\$dir_section/\$tide_pwd_markers
set split_output[\$i] \"$color_anchors\$dir_section$reset_to_color_dirs\"
else if test \$_tide_pwd_len -gt \$dist_btwn_sides
string match -qr \"(?<trunc>\..|.)\" \$dir_section
string match -qr \"(?<trunc>\..|.)\" -- \$dir_section

set -l glob \$parent_dir/\$trunc*/
set -e glob[(contains -i \$parent_dir/\$dir_section/ \$glob)] # This is faster than inverse string match

while string match -qr \"^\$parent_dir/\$(string escape --style=regex \$trunc)\" \$glob &&
string match -qr \"(?<trunc>\$(string escape --style=regex \$trunc).)\" \$dir_section
while string match -qr \"^\$parent_dir/\$(string escape --style=regex -- \$trunc)\" \$glob &&
string match -qr \"(?<trunc>\$(string escape --style=regex -- \$trunc).)\" -- \$dir_section
end
test -n \"\$trunc\" && set split_output[\$i] \"$color_truncated\$trunc$reset_to_color_dirs\" &&
string join / \$split_output | string length -V | read _tide_pwd_len
string join / -- \$split_output | string length -V | read _tide_pwd_len
end
end

Expand Down
9 changes: 9 additions & 0 deletions tests/_tide_item_pwd.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ _pwd "$tmpdir/tmp/has spaces/foo" # CHECK: ~/tmp/has spaces/foo

mkdir -p "$tmpdir/tmp/--has dashes/foo"
_pwd "$tmpdir/tmp/--has dashes/foo" # CHECK: ~/tmp/--has dashes/foo
command rm -r "$tmpdir/tmp/--has dashes"

mkdir -p "$tmpdir/tmp/has'quotes''/foo"
_pwd "$tmpdir/tmp/has'quotes''/foo" # CHECK: ~/tmp/has'quotes''/foo
Expand All @@ -130,5 +131,13 @@ mkdir -p "$tmpdir/tmp/[hello"
_pwd $tmpdir/tmp/$longDirWithDot # CHECK: ~/t/[t/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa
command rm -r "$tmpdir/tmp/[hello"

# ---------- Truncation with a leading-dash directory ----------
set -l longDirDash -alfa/bravo/charlie/delta/echo/foxtrot/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa
_pwd $tmpdir/tmp/$longDirDash # CHECK: ~/t/-/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa

mkdir -p $tmpdir/tmp/-alfawolf
_pwd $tmpdir/tmp/$longDirDash # CHECK: ~/t/-alfa/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa
command rm -r $tmpdir/tmp/-alfawolf

# ------------------------------------Cleanup------------------------------------
command rm -r $tmpdir
Loading