@@ -137,20 +137,20 @@ remove_note() {
137137 rm " ${rm_args[@]} " " $to_remove "
138138}
139139
140- open_something () {
140+ handle_multiple_notes () {
141+ local cmd=$1
142+
141143 if [[ -p /dev/stdin ]]; then
142144 read -d' \n' note_names
143145 while read note_name; do
144- open_note " $note_name "
146+ ${cmd} _note " $note_name "
145147 done <<< " $note_names"
146- elif [ $# -gt 0 ]; then
147- open_note " $* "
148148 else
149- open $notes_dir
149+ ${cmd} _note " ${ @: 2} "
150150 fi
151151}
152152
153- open_note () {
153+ get_full_note_path () {
154154 local note_path=$1
155155
156156 if [[ " $note_path " != * .$NOTES_EXT ]]; then
@@ -159,14 +159,41 @@ open_note() {
159159 if [ ! -f " $note_path " ]; then
160160 note_path=" $notes_dir /$note_path "
161161 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+
162174 if [ -z " $EDITOR " ]; then
163175 printf " Please set \$ EDITOR to edit notes\n"
164176 exit 1
165177 fi
166178
179+ note_path=$( get_full_note_path " $note_path " )
180+
167181 $EDITOR " $note_path " < /dev/tty
168182}
169183
184+ cat_note () {
185+ local note_path=$1
186+
187+ if [[ -z " $note_path " ]]; then
188+ printf " Cat requires a name, but none was provided."
189+ exit 1
190+ fi
191+
192+ note_path=$( get_full_note_path " $note_path " )
193+
194+ cat " $note_path "
195+ }
196+
170197usage () {
171198 cat << EOF
172199notes is a command line note taking tool.
@@ -180,7 +207,9 @@ Usage:
180207 notes open|o # Open your notes directory
181208 notes open|o <name> # Open a note for editing by full name
182209 notes rm [-r | --recursive] <name> # Remove note, or folder if -r or --recursive is given
210+ notes cat <name> # Display note
183211 echo <name> | notes open|o # Open all note filenames piped in
212+ echo <name> | notes cat # Display all note filenames piped in
184213 notes --help # Print this usage information
185214
186215'command|c' means you can use 'command' or the equivalent shorthand alias 'c'
@@ -217,11 +246,14 @@ main() {
217246 cmd=" grep_notes"
218247 ;;
219248 " open" |" o" )
220- cmd=" open_something "
249+ cmd=" handle_multiple_notes open "
221250 ;;
222251 " rm" )
223252 cmd=" remove_note"
224253 ;;
254+ " cat" )
255+ cmd=" handle_multiple_notes cat"
256+ ;;
225257 --help | -help | -h )
226258 cmd=" usage"
227259 ;;
0 commit comments