File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -19,11 +19,19 @@ without_notes_dir() {
19
19
}
20
20
21
21
ls_notes () {
22
- ls_output=$( ls -p " $notes_dir /$* " 2>&1 )
23
- ls_result=$?
22
+ local ls_output=$( ls -p " $notes_dir /$* " 2>&1 )
23
+ local ls_result=$?
24
+ local formatted_output
24
25
25
- if [[ $ls_result == 0 && " $ls_output " ]]; then
26
- printf " $ls_output \n"
26
+ if [ $# -gt 0 ]; then
27
+ local path_prefix=$( printf " ${*%/ } " | sed -e ' s/[]\/$*.^|[]/\\&/g' )
28
+ formatted_output=$( printf " $ls_output " | sed -E " s/^/$path_prefix \//" )
29
+ else
30
+ formatted_output=$ls_output
31
+ fi
32
+
33
+ if [[ $ls_result == 0 && " $formatted_output " ]]; then
34
+ printf " $formatted_output \n"
27
35
return 0
28
36
else
29
37
return 2
Original file line number Diff line number Diff line change @@ -66,5 +66,16 @@ notes="./notes"
66
66
assert_success
67
67
refute_line " hide-note.md"
68
68
refute_line " match-dir/"
69
- assert_line " match-note1.md"
69
+ assert_line " match-dir/match- note1.md"
70
70
}
71
+
72
+ @test " Should list contents of a subdirectory if the pattern includes slashes" {
73
+ mkdir -p $NOTES_DIRECTORY /match-dir/child-dir
74
+ touch $NOTES_DIRECTORY /match-dir/child-dir/match-note1.md
75
+
76
+ run $notes ls match-dir/child-dir/
77
+
78
+ assert_success
79
+ assert_line " match-dir/child-dir/match-note1.md"
80
+ }
81
+
You can’t perform that action at this time.
0 commit comments