diff --git a/functions/_tide_pwd.fish b/functions/_tide_pwd.fish index fe7b51f..7c52d6c 100644 --- a/functions/_tide_pwd.fish +++ b/functions/_tide_pwd.fish @@ -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 \"(?\..|.)\" \$dir_section + string match -qr \"(?\..|.)\" -- \$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 \"(?\$(string escape --style=regex \$trunc).)\" \$dir_section + while string match -qr \"^\$parent_dir/\$(string escape --style=regex -- \$trunc)\" -- \$glob && + string match -qr \"(?\$(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 diff --git a/tests/_tide_item_pwd.test.fish b/tests/_tide_item_pwd.test.fish index b49cbc2..4b6a9fc 100644 --- a/tests/_tide_item_pwd.test.fish +++ b/tests/_tide_item_pwd.test.fish @@ -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