File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ There are also more complex options available. You can set any configuration pro
97
97
* ` NOTES_EXT ` changes the default extension that notes are saved with.
98
98
* ` NOTES_DIRECTORY ` changes the directory in which notes are stored.
99
99
* ` EDITOR ` can also be overriden here, for ` notes ` only.
100
+ * ` POST_COMMAND ` sets the command to run after any modification command (e.g. ` open ` , ` mv ` , ...) succeeds
100
101
101
102
102
103
## How do I use it?
Original file line number Diff line number Diff line change 13
13
14
14
# Define the directory where notes are stored
15
15
# NOTES_DIRECTORY=~/notes
16
+
17
+ # Define command to run after modification command
18
+ # POST_COMMAND="/path/to/custom_script.sh"
Original file line number Diff line number Diff line change 316
316
main () {
317
317
local ret=0
318
318
local cmd=" "
319
+ # variable to indicate whether it's a modification command
320
+ local modified=0
319
321
320
322
if [ -z " $1 " ]; then
321
323
printf " No command specified\n\n"
@@ -326,6 +328,7 @@ main() {
326
328
case " $1 " in
327
329
" new" |" n" )
328
330
cmd=" new_note"
331
+ modified=1
329
332
;;
330
333
" ls" )
331
334
cmd=" ls_notes"
@@ -341,15 +344,19 @@ main() {
341
344
;;
342
345
" open" |" o" )
343
346
cmd=" handle_multiple_notes open"
347
+ modified=1
344
348
;;
345
349
" append" |" a" )
346
350
cmd=" append_note"
351
+ modified=1
347
352
;;
348
353
" mv" )
349
354
cmd=" move_note"
355
+ modified=1
350
356
;;
351
357
" rm" )
352
358
cmd=" remove_note"
359
+ modified=1
353
360
;;
354
361
" cat" )
355
362
cmd=" handle_multiple_notes cat"
@@ -370,6 +377,12 @@ main() {
370
377
371
378
$cmd " $@ "
372
379
ret=$[$ret +$? ]
380
+
381
+ # run POST_COMMAND hook when modification cmd succeeds
382
+ if [ $ret -eq 0 ] && [ $modified -eq 1 ] && [ -n " $POST_COMMAND " ]; then
383
+ eval " $POST_COMMAND "
384
+ fi
385
+
373
386
exit $ret
374
387
}
375
388
main " $@ "
Original file line number Diff line number Diff line change @@ -57,4 +57,24 @@ notes="./notes"
57
57
58
58
assert_failure
59
59
assert_line " Could not create directory $NOTES_DIRECTORY /testfile, please update your \$ NOTES_DIRECTORY"
60
- }
60
+ }
61
+
62
+ @test " Post-command should run if it is a modification command" {
63
+ mkdir -p $HOME /.config/notes
64
+ echo ' POST_COMMAND="echo 1 > $HOME/post-output"' > $HOME /.config/notes/config
65
+ run $notes new test
66
+
67
+ assert_success
68
+ assert_exists $HOME /post-output
69
+ }
70
+
71
+ @test " Post-command should not run if it is not a modification command" {
72
+ run $notes new test
73
+
74
+ mkdir -p $HOME /.config/notes
75
+ echo ' POST_COMMAND="echo 1 > $HOME/post-output"' > $HOME /.config/notes/config
76
+ run $notes cat test
77
+
78
+ assert_success
79
+ refute_exists $HOME /post-output
80
+ }
You can’t perform that action at this time.
0 commit comments