Skip to content
Merged
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 @@ -29,16 +29,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; or echo 1..-1)] # 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
12 changes: 12 additions & 0 deletions tests/_tide_item_pwd.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ _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

# ---------- Truncation with a leading-dash directory (regression: upstream #668) ----------
set -l longDashDir -alfa/bravo/charlie/delta/echo/foxtrot/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa
# trunc disambiguates against the sibling "--has dashes" dir made above
_pwd $tmpdir/tmp/$longDashDir # CHECK: ~/t/-a/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa

# Same-prefix sibling forces the disambiguation loop to grow trunc past the
# leading dash -- this used to hang because `string escape --style=regex`
# choked on it without `--`.
mkdir -p "$tmpdir/tmp/-alfahello"
_pwd $tmpdir/tmp/$longDashDir # CHECK: ~/t/-alfa/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa
command rm -r "$tmpdir/tmp/-alfahello"

mkdir -p "$tmpdir/tmp/has'quotes''/foo"
_pwd "$tmpdir/tmp/has'quotes''/foo" # CHECK: ~/tmp/has'quotes''/foo

Expand Down
Loading