@@ -137,20 +137,20 @@ remove_note() {
137
137
rm " ${rm_args[@]} " " $to_remove "
138
138
}
139
139
140
- open_something () {
140
+ handle_multiple_notes () {
141
+ local cmd=$1
142
+
141
143
if [[ -p /dev/stdin ]]; then
142
144
read -d' \n' note_names
143
145
while read note_name; do
144
- open_note " $note_name "
146
+ ${cmd} _note " $note_name "
145
147
done <<< " $note_names"
146
- elif [ $# -gt 0 ]; then
147
- open_note " $* "
148
148
else
149
- open $notes_dir
149
+ ${cmd} _note " ${ @: 2} "
150
150
fi
151
151
}
152
152
153
- open_note () {
153
+ get_full_note_path () {
154
154
local note_path=$1
155
155
156
156
if [[ " $note_path " != * .$NOTES_EXT ]]; then
@@ -159,38 +159,38 @@ open_note() {
159
159
if [ ! -f " $note_path " ]; then
160
160
note_path=" $notes_dir /$note_path "
161
161
fi
162
+
163
+ echo " $note_path "
164
+ }
165
+
166
+ open_note () {
167
+ local note_path=$1
168
+
169
+ if [[ -z " $note_path " ]]; then
170
+ open $notes_dir
171
+ return
172
+ fi
173
+
162
174
if [ -z " $EDITOR " ]; then
163
175
printf " Please set \$ EDITOR to edit notes\n"
164
176
exit 1
165
177
fi
166
178
167
- $EDITOR " $note_path " < /dev/tty
168
- }
179
+ note_path=$( get_full_note_path " $note_path " )
169
180
170
- cat_something () {
171
- if [[ -p /dev/stdin ]]; then
172
- read -d' \n' note_names
173
- while read note_name; do
174
- cat_note " $note_name "
175
- done <<< " $note_names"
176
- elif [ $# -gt 0 ]; then
177
- cat_note " $* "
178
- else
179
- printf " Cat requires a name, but none was provided."
180
- return 1
181
- fi
181
+ $EDITOR " $note_path " < /dev/tty
182
182
}
183
183
184
184
cat_note () {
185
185
local note_path=$1
186
186
187
- if [[ " $note_path " != * .$NOTES_EXT ]]; then
188
- note_path=" $note_path .$NOTES_EXT "
189
- fi
190
- if [ ! -f " $note_path " ]; then
191
- note_path=" $notes_dir /$note_path "
187
+ if [[ -z " $note_path " ]]; then
188
+ printf " Cat requires a name, but none was provided."
189
+ exit 1
192
190
fi
193
191
192
+ note_path=$( get_full_note_path " $note_path " )
193
+
194
194
cat " $note_path "
195
195
}
196
196
@@ -246,13 +246,13 @@ main() {
246
246
cmd=" grep_notes"
247
247
;;
248
248
" open" |" o" )
249
- cmd=" open_something "
249
+ cmd=" handle_multiple_notes open "
250
250
;;
251
251
" rm" )
252
252
cmd=" remove_note"
253
253
;;
254
254
" cat" )
255
- cmd=" cat_something "
255
+ cmd=" handle_multiple_notes cat "
256
256
;;
257
257
--help | -help | -h )
258
258
cmd=" usage"
0 commit comments