Skip to content

Commit 9886c59

Browse files
committed
Update dev to latest src
1 parent b6e1f74 commit 9886c59

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

_notes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ __notes_cmd ()
4646
ls:'<pattern> List notes by path'
4747
find:'[pattern] Search notes by filename and path'
4848
grep:'<pattern> Search notes by content'
49+
search:'[pattern] Search notes by filename or content'
4950
open:'<name> Open a notes for editing by full name'
5051
rm:'[-r | --recursive] <name> Remove note, or folder if -r or --recursive is given]'
5152
--help:'Show usage'

notes

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ ls_notes() {
4343
fi
4444
}
4545

46+
search_filenames_and_contents() {
47+
if [ "$#" -gt 0 ]; then
48+
find_output=$(find "$notes_dir" -type f -exec bash -c \
49+
"shopt -s nocasematch
50+
grep -il \"$*\" \"{}\" || if [[ \"{}\" =~ \"$*\" ]]; then
51+
echo \"{}\";
52+
fi" \;\
53+
)
54+
else
55+
find_output=$(find "$notes_dir" -type f)
56+
fi
57+
find_result=$?
58+
formatted_output=$(printf "$find_output" | without_notes_dir)
59+
60+
if [[ $find_result == 0 && "$formatted_output" ]]; then
61+
printf "$formatted_output\n"
62+
return 0
63+
else
64+
return 2
65+
fi
66+
}
67+
4668
find_notes() {
4769
local find_output=$(find "$notes_dir" -ipath "$notes_dir/*$**" -type f 2>&1)
4870
local find_result=$?
@@ -181,6 +203,7 @@ Usage:
181203
notes ls <pattern> # List notes by path
182204
notes find|f [pattern] # Search notes by filename and path
183205
notes grep|g <pattern> # Search notes by content
206+
notes search|s [pattern] # Search notes by filename or content
184207
notes open|o # Open your notes directory
185208
notes open|o <name> # Open a note for editing by full name
186209
notes rm [-r | --recursive] <name> # Remove note, or folder if -r or --recursive is given
@@ -211,6 +234,9 @@ main() {
211234
"ls" )
212235
cmd="ls_notes"
213236
;;
237+
"search"|"s")
238+
cmd="search_filenames_and_contents"
239+
;;
214240
"find"|"f" )
215241
cmd="find_notes"
216242
;;

0 commit comments

Comments
 (0)