Skip to content

Commit

Permalink
Fix parent dir bugs (#346), pwd bugs, add regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IlanCosman committed Sep 15, 2022
1 parent 98b087a commit 22c230c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
9 changes: 5 additions & 4 deletions functions/_tide_parent_dirs.fish
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions functions/_tide_pwd.fish
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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\"
else
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
Expand Down
10 changes: 10 additions & 0 deletions tests/_tide_item_pwd.test.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 27 additions & 0 deletions tests/_tide_parent_dirs.test.fish
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 22c230c

Please sign in to comment.