@@ -56,8 +56,7 @@ search_filenames_and_contents() {
56
56
" shopt -s nocasematch
57
57
grep -il \" $* \" \" {}\" || if [[ \" {}\" =~ \" $* \" ]]; then
58
58
echo \" {}\" ;
59
- fi" \; \
60
- )
59
+ fi" \; )
61
60
else
62
61
find_output=$( find " $notes_dir " -type f)
63
62
fi
@@ -105,12 +104,11 @@ grep_notes() {
105
104
106
105
generate_name () {
107
106
local append_num=0
108
- local format_string=" ` date +$QUICKNOTE_FORMAT ` "
107
+ local format_string=" $( date +$QUICKNOTE_FORMAT ) "
109
108
# Initial test has no append
110
109
local resolved_name=$format_string
111
- while [[ -e " $notes_dir /$resolved_name .$NOTES_EXT " ]]
112
- do
113
- append_num=$[$append_num +1]
110
+ while [[ -e " $notes_dir /$resolved_name .$NOTES_EXT " ]]; do
111
+ append_num=$(( $append_num + 1 ))
114
112
resolved_name=$format_string .$append_num
115
113
done
116
114
printf $resolved_name
@@ -119,10 +117,10 @@ generate_name() {
119
117
new_note () {
120
118
local note_name=" $* "
121
119
if [[ $note_name == " " ]]; then
122
- note_name=" $( generate_name) "
120
+ note_name=" $( generate_name) "
123
121
fi
124
122
125
- if echo " $note_name " | grep " /$" & > /dev/null; then
123
+ if echo " $note_name " | grep " /$" & > /dev/null; then
126
124
note_name=" ${note_name} /$( generate_name) "
127
125
fi
128
126
@@ -161,7 +159,7 @@ handle_multiple_notes() {
161
159
read -d' \n' note_names
162
160
while read note_name; do
163
161
${cmd} _note " $note_name "
164
- done <<< " $note_names"
162
+ done <<< " $note_names"
165
163
else
166
164
${cmd} _note " ${@: 2} "
167
165
fi
@@ -202,7 +200,7 @@ open_note() {
202
200
exit 1
203
201
fi
204
202
205
- note_path=$( get_full_note_path " $note_path " )
203
+ note_path=$( get_full_note_path " $note_path " )
206
204
207
205
if bash -c " : >/dev/tty" > /dev/null 2> /dev/null; then
208
206
$EDITOR " $note_path " < /dev/tty
@@ -212,7 +210,7 @@ open_note() {
212
210
}
213
211
214
212
append_note () {
215
- local source_note_path=$( get_full_note_path " $1 " )
213
+ local source_note_path=$( get_full_note_path " $1 " )
216
214
local to_append=" ${@: 2} "
217
215
218
216
# If no note name was provided, exit
@@ -237,11 +235,11 @@ append_note() {
237
235
exit 1
238
236
fi
239
237
240
- echo " $to_append " >> " $source_note_path "
238
+ echo " $to_append " >> " $source_note_path "
241
239
}
242
240
243
241
move_note () {
244
- local source_note_path=$( get_full_note_path " $1 " )
242
+ local source_note_path=$( get_full_note_path " $1 " )
245
243
local dest_or_dir_path=$2
246
244
247
245
if [[ ! -e " $source_note_path " ]]; then
@@ -260,8 +258,8 @@ move_note() {
260
258
return
261
259
fi
262
260
263
- local dest_path=$( get_full_note_path " $dest_or_dir_path " )
264
- mkdir -p " $( dirname $dest_path ) "
261
+ local dest_path=$( get_full_note_path " $dest_or_dir_path " )
262
+ mkdir -p " $( dirname $dest_path ) "
265
263
mv $source_note_path $dest_path
266
264
}
267
265
@@ -273,14 +271,14 @@ cat_note() {
273
271
exit 1
274
272
fi
275
273
276
- note_path=$( get_full_note_path " $note_path " )
274
+ note_path=$( get_full_note_path " $note_path " )
277
275
278
276
cat " $note_path "
279
277
}
280
278
281
279
usage () {
282
- local name=$( basename $0 )
283
- cat << EOF
280
+ local name=$( basename $0 )
281
+ cat << EOF
284
282
$name is a command line note taking tool.
285
283
286
284
Usage:
@@ -294,7 +292,7 @@ Usage:
294
292
$name append|a <name> [message] # Appends a note. Will use stdin if no message is given
295
293
$name mv <source> <dest>|<directory> # Rename a note, or move a note when a directory is given
296
294
$name rm [-r | --recursive] <name> # Remove note, or folder if -r or --recursive is given
297
- $name cat <name> # Display note
295
+ $name cat|c <name> # Display note
298
296
echo <name> | $name open|o # Open all note filenames piped in
299
297
echo <name> | $name cat # Display all note filenames piped in
300
298
$name --help # Print this usage information
307
305
}
308
306
309
307
version () {
310
- local name=$( basename $0 )
311
- cat << EOF
308
+ local name=$( basename $0 )
309
+ cat << EOF
312
310
$name $notes_version
313
311
EOF
314
312
}
@@ -326,57 +324,57 @@ main() {
326
324
fi
327
325
328
326
case " $1 " in
329
- " new" | " n" )
330
- cmd=" new_note"
331
- modified=1
332
- ;;
333
- " ls" )
334
- cmd=" ls_notes"
335
- ;;
336
- " search" | " s" )
337
- cmd=" search_filenames_and_contents"
338
- ;;
339
- " find" | " f" )
340
- cmd=" find_notes"
341
- ;;
342
- " grep" | " g" )
343
- cmd=" grep_notes"
344
- ;;
345
- " open" | " o" )
346
- cmd=" handle_multiple_notes open"
347
- modified=1
348
- ;;
349
- " append" | " a" )
350
- cmd=" append_note"
351
- modified=1
352
- ;;
353
- " mv" )
354
- cmd=" move_note"
355
- modified=1
356
- ;;
357
- " rm" )
358
- cmd=" remove_note"
359
- modified=1
360
- ;;
361
- " cat" )
362
- cmd=" handle_multiple_notes cat"
363
- ;;
364
- --help | -help | -h )
365
- cmd=" usage"
366
- ;;
367
- --version | -version )
368
- cmd=" version"
369
- ;;
370
- * )
371
- printf " $1 is not a recognized notes command.\n\n"
372
- cmd=" usage"
373
- ret=1
374
- ;;
327
+ " new" | " n" )
328
+ cmd=" new_note"
329
+ modified=1
330
+ ;;
331
+ " ls" )
332
+ cmd=" ls_notes"
333
+ ;;
334
+ " search" | " s" )
335
+ cmd=" search_filenames_and_contents"
336
+ ;;
337
+ " find" | " f" )
338
+ cmd=" find_notes"
339
+ ;;
340
+ " grep" | " g" )
341
+ cmd=" grep_notes"
342
+ ;;
343
+ " open" | " o" )
344
+ cmd=" handle_multiple_notes open"
345
+ modified=1
346
+ ;;
347
+ " append" | " a" )
348
+ cmd=" append_note"
349
+ modified=1
350
+ ;;
351
+ " mv" )
352
+ cmd=" move_note"
353
+ modified=1
354
+ ;;
355
+ " rm" )
356
+ cmd=" remove_note"
357
+ modified=1
358
+ ;;
359
+ " cat" | " c " )
360
+ cmd=" handle_multiple_notes cat"
361
+ ;;
362
+ --help | -help | -h)
363
+ cmd=" usage"
364
+ ;;
365
+ --version | -version)
366
+ cmd=" version"
367
+ ;;
368
+ * )
369
+ printf " $1 is not a recognized notes command.\n\n"
370
+ cmd=" usage"
371
+ ret=1
372
+ ;;
375
373
esac
376
374
shift
377
375
378
376
$cmd " $@ "
379
- ret=$[ $ret + $? ]
377
+ ret=$(( $ret + $? ))
380
378
381
379
# run POST_COMMAND hook when modification cmd succeeds
382
380
if [ $ret -eq 0 ] && [ $modified -eq 1 ] && [ -n " $POST_COMMAND " ]; then
@@ -386,4 +384,3 @@ main() {
386
384
exit $ret
387
385
}
388
386
main " $@ "
389
-
0 commit comments