diff --git a/functions/_tide_parent_dirs.fish b/functions/_tide_parent_dirs.fish index dcc7a741..9f31b043 100644 --- a/functions/_tide_parent_dirs.fish +++ b/functions/_tide_parent_dirs.fish @@ -1,6 +1,7 @@ function _tide_parent_dirs --on-variable PWD - set -g _tide_parent_dirs (for dir in (string split / $PWD) - set -la parts $dir - string join / $parts - end) + set -g _tide_parent_dirs (string escape ( + for dir in (string split / -- $PWD) + set -la parts $dir + string join / -- $parts + end)) end diff --git a/functions/_tide_pwd.fish b/functions/_tide_pwd.fish index 1680528e..3bd53b0f 100644 --- a/functions/_tide_pwd.fish +++ b/functions/_tide_pwd.fish @@ -7,7 +7,7 @@ set -l home_icon $tide_pwd_icon_home' ' set -l pwd_icon $tide_pwd_icon' ' eval "function _tide_pwd - if set -l split_pwd (string replace -r '^$HOME' '~' \$PWD | string split /) + if set -l split_pwd (string replace -r '^$HOME' '~' -- \$PWD | string split /) test -w . && set -f split_output \"$pwd_icon\$split_pwd[1]\" \$split_pwd[2..] || set -f split_output \"$unwritable_icon\$split_pwd[1]\" \$split_pwd[2..] set split_output[-1] \"$color_anchors\$split_output[-1]$reset_to_color_dirs\" @@ -15,7 +15,7 @@ eval "function _tide_pwd set -f split_output \"$home_icon$color_anchors~\" end - string join / \$split_output | string length -V | read -g _tide_pwd_len + string join / -- \$split_output | string length -V | read -g _tide_pwd_len 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 diff --git a/tests/_tide_item_pwd.test.fish b/tests/_tide_item_pwd.test.fish index 52960319..3eccda7e 100644 --- a/tests/_tide_item_pwd.test.fish +++ b/tests/_tide_item_pwd.test.fish @@ -104,5 +104,15 @@ mkdir -p $tmpdir/tmp/.git _pwd $tmpdir/tmp/$longDir # CHECK: ~/tmp/a/b/c/d/e/f/golf/hotel/india/juliett/kilo/lima/mike/november/oscar/papa command rm -r $tmpdir/tmp/.git +# ------------------------------------Weird Directories------------------------------------ +mkdir -p "$tmpdir/tmp/has spaces/foo" +_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 + +mkdir -p "$tmpdir/tmp/has'quotes''/foo" +_pwd "$tmpdir/tmp/has'quotes''/foo" # CHECK: ~/tmp/has'quotes''/foo + # ------------------------------------Cleanup------------------------------------ command rm -r $tmpdir diff --git a/tests/_tide_parent_dirs.test.fish b/tests/_tide_parent_dirs.test.fish new file mode 100644 index 00000000..8c5c482f --- /dev/null +++ b/tests/_tide_parent_dirs.test.fish @@ -0,0 +1,27 @@ +# RUN: %fish %s +_tide_parent_dirs + +function _parent_dirs -a dir + cd $dir + eval "set _tide_parent_dirs $_tide_parent_dirs" + path is $_tide_parent_dirs/test.foo && echo found +end + +set -l tmpdir (mktemp -d) + +mkdir -p "$tmpdir/tmp/has spaces/foo" +_parent_dirs "$tmpdir/tmp/has spaces/foo" # CHECK: +touch "$tmpdir/tmp/has spaces/test.foo" +_parent_dirs "$tmpdir/tmp/has spaces/foo" # CHECK: found + +mkdir -p "$tmpdir/tmp/--has dashes/foo" +_parent_dirs "$tmpdir/tmp/--has dashes/foo" # CHECK: +touch "$tmpdir/tmp/--has dashes/test.foo" +_parent_dirs "$tmpdir/tmp/--has dashes/foo" # CHECK: found + +mkdir -p "$tmpdir/tmp/has'quotes''/foo" +_parent_dirs "$tmpdir/tmp/has'quotes''/foo" # CHECK: +touch "$tmpdir/tmp/has'quotes''/test.foo" +_parent_dirs "$tmpdir/tmp/has'quotes''/foo" # CHECK: found + +command rm -r $tmpdir