1
1
#! /usr/bin/env bash
2
2
3
+ GREP_COLOR=always
4
+
3
5
# Look for configuration file at ~/.config/notes/config and use it
4
- if [ -f ~ /.config/notes/config ]; then
6
+ if [ -f ~ /.config/notes/config ]; then
5
7
. ~ /.config/notes/config
6
8
fi
7
9
@@ -15,7 +17,7 @@ if [ -z "$EDITOR" ] && type editor &>/dev/null; then
15
17
fi
16
18
17
19
without_notes_dir () {
18
- cat | sed -e " s/^ $escaped_notes_dir //g" | sed -E " s/^\/+//g"
20
+ cat | sed -e " s/$escaped_notes_dir //g" | sed -E " s/^\/+//g"
19
21
}
20
22
21
23
ls_notes () {
@@ -53,11 +55,22 @@ find_notes() {
53
55
54
56
grep_notes () {
55
57
if [ ! " $# " -gt 0 ]; then
56
- printf " Grep requires a pattern, but none was provided."
58
+ printf " Grep requires a pattern, but none was provided.\n "
57
59
return 1
58
60
fi
59
61
60
- local grep_output=$( grep -r " $notes_dir " -li -e " $* " 2>&1 )
62
+ local grep_output
63
+ if [[ -t 1 ]]; then
64
+ matches=$( grep --color=$GREP_COLOR -r $NOTES_DIRECTORY -in -e " $* " 2>&1 )
65
+ IFS=$' \n '
66
+ for result in $matches ; do
67
+ len=${# result}
68
+ grep_output+=" $( echo ${result} ) \n"
69
+ done
70
+ else
71
+ grep_output=$( grep -r " $notes_dir " -li -e " $* " 2>&1 )
72
+ fi
73
+
61
74
local grep_result=$?
62
75
local formatted_output=$( printf " $grep_output " | without_notes_dir)
63
76
@@ -94,9 +107,11 @@ remove_note() {
94
107
open_something () {
95
108
if [[ -p /dev/stdin ]]; then
96
109
read -d' \n' note_names
110
+ local buffer=()
97
111
while read note_name; do
98
- open_note " $note_name "
112
+ buffer+= $note_name
99
113
done <<< " $note_names"
114
+ open_note $note_names
100
115
elif [ $# -gt 0 ]; then
101
116
open_note " $* "
102
117
else
@@ -105,20 +120,25 @@ open_something() {
105
120
}
106
121
107
122
open_note () {
108
- local note_path=$1
109
-
110
- if [[ " $note_path " != * .md ]]; then
111
- note_path=" $note_path .md"
112
- fi
113
- if [ ! -f " $note_path " ]; then
114
- note_path=" $notes_dir /$note_path "
115
- fi
116
- if [ -z " $EDITOR " ]; then
117
- printf " Please set \$ EDITOR to edit notes\n"
118
- exit 1
119
- fi
120
-
121
- $EDITOR " $note_path " < /dev/tty
123
+ local note_path
124
+ local buffer=()
125
+
126
+ for arg in $@ ; do
127
+ note_path=$arg
128
+ if [[ " $note_path " != * .md ]]; then
129
+ note_path=" $note_path .md"
130
+ fi
131
+ if [ ! -f " $note_path " ]; then
132
+ note_path=" $notes_dir /$note_path "
133
+ fi
134
+ if [ -z " $EDITOR " ]; then
135
+ printf " Please set \$ EDITOR to edit notes\n"
136
+ exit 1
137
+ fi
138
+ buffer+=" $note_path "
139
+ done
140
+
141
+ $EDITOR $buffer < /dev/tty
122
142
}
123
143
124
144
usage () {
0 commit comments