File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ __notes_cmd ()
46
46
ls:' <pattern> List notes by path'
47
47
find:' [pattern] Search notes by filename and path'
48
48
grep:' <pattern> Search notes by content'
49
+ search:' [pattern] Search notes by filename or content'
49
50
open:' <name> Open a notes for editing by full name'
50
51
rm:' [-r | --recursive] <name> Remove note, or folder if -r or --recursive is given]'
51
52
--help:' Show usage'
Original file line number Diff line number Diff line change @@ -43,6 +43,28 @@ ls_notes() {
43
43
fi
44
44
}
45
45
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
+
46
68
find_notes () {
47
69
local find_output=$( find " $notes_dir " -ipath " $notes_dir /*$* *" -type f 2>&1 )
48
70
local find_result=$?
@@ -181,6 +203,7 @@ Usage:
181
203
notes ls <pattern> # List notes by path
182
204
notes find|f [pattern] # Search notes by filename and path
183
205
notes grep|g <pattern> # Search notes by content
206
+ notes search|s [pattern] # Search notes by filename or content
184
207
notes open|o # Open your notes directory
185
208
notes open|o <name> # Open a note for editing by full name
186
209
notes rm [-r | --recursive] <name> # Remove note, or folder if -r or --recursive is given
@@ -211,6 +234,9 @@ main() {
211
234
" ls" )
212
235
cmd=" ls_notes"
213
236
;;
237
+ " search" |" s" )
238
+ cmd=" search_filenames_and_contents"
239
+ ;;
214
240
" find" |" f" )
215
241
cmd=" find_notes"
216
242
;;
You can’t perform that action at this time.
0 commit comments