@@ -8,7 +8,6 @@ if [ -f ~/.config/notes/config ]; then
8
8
. ~ /.config/notes/config
9
9
fi
10
10
11
- file_ext=$PREFERED_EXT
12
11
configured_dir=${NOTES_DIRECTORY%/ } # Remove trailing slashes
13
12
notes_dir=" ${configured_dir:- $HOME / notes} "
14
13
escaped_notes_dir=" $( printf " $notes_dir " | sed -e ' s/[]\/$*.^|[]/\\&/g' ) "
@@ -79,25 +78,11 @@ find_notes() {
79
78
80
79
grep_notes () {
81
80
if [ ! " $# " -gt 0 ]; then
82
- printf " Grep requires a pattern, but none was provided.\n "
81
+ printf " Grep requires a pattern, but none was provided."
83
82
return 1
84
83
fi
85
84
86
- local grep_output
87
- if [[ -t 1 ]]; then
88
- matches=$( grep --color=$GREP_COLOR -r $NOTES_DIRECTORY -in -e " $* " 2>&1 )
89
- OLDIFS=$IFS
90
- IFS=$' \n '
91
- for result in $matches ; do
92
- len=${# result}
93
- result=$( echo $result | cut -d' /' -f2-)
94
- grep_output+=" $( echo /${result} ) \n"
95
- done
96
- IFS=$OLDIFS
97
- else
98
- grep_output=$( grep -r " $notes_dir " -li -e " $* " 2>&1 )
99
- fi
100
-
85
+ local grep_output=$( grep -r " $notes_dir " -li -e " $* " 2>&1 )
101
86
local grep_result=$?
102
87
local formatted_output=$( printf " $grep_output " | without_notes_dir)
103
88
@@ -128,38 +113,31 @@ new_note() {
128
113
note_name=" $( generate_name) "
129
114
fi
130
115
mkdir -p " $( dirname " $notes_dir /$note_name " ) "
131
- open_note " $note_name "
116
+ open_note " $note_name . $NOTES_EXT "
132
117
}
133
118
134
119
remove_note () {
135
120
local rm_args=()
136
- local len=${#@ }
137
-
138
121
if [[ " $1 " == " -r" || " $1 " == " --recursive" ]]; then
139
122
rm_args+=(" --recursive" )
140
123
shift
141
124
fi
142
125
143
- len=${#@ }
144
- for i in $( seq 1 $len ) ; do
145
- local note_name=" $1 "
146
- local to_remove=" $notes_dir /$note_name "
126
+ local note_name=" $* "
127
+ local to_remove=" $notes_dir /$note_name "
147
128
148
- if [ -f " $notes_dir /$note_name$file_ext " ]; then
149
- to_remove=" $notes_dir /$note_name$file_ext "
150
- fi
151
- rm " ${rm_args[@]} " " $to_remove "
152
- shift
153
- done
129
+ if [ -f " $notes_dir /$note_name .$NOTES_EXT " ]; then
130
+ to_remove=" $notes_dir /$note_name .$NOTES_EXT "
131
+ fi
132
+ rm " ${rm_args[@]} " " $to_remove "
154
133
}
155
134
156
135
open_something () {
157
136
if [[ -p /dev/stdin ]]; then
158
- read -d $" \n " note_names
137
+ read -d' \n ' note_names
159
138
while read note_name; do
160
- buffer+= " ${ note_name} , "
139
+ open_note " $ note_name"
161
140
done <<< " $note_names"
162
- open_note ${buffer[@]}
163
141
elif [ $# -gt 0 ]; then
164
142
open_note " $* "
165
143
else
@@ -168,33 +146,24 @@ open_something() {
168
146
}
169
147
170
148
open_note () {
171
- local note_path
172
- local ext_check
173
- local buffer=$@
174
- local files=()
149
+ local note_path=$1
175
150
176
- OLDIFS=$IFS ; IFS=' ,'
177
- for file in $buffer ; do
178
- note_path=$file
179
- ext_check=$( echo ${note_path: 1:- 1} | grep -e ' \.[a-z]' )
180
- if [[ -z ${ext_check} ]]; then
181
- note_path=" $note_path$file_ext "
182
- fi
183
- if [ ! -f " $note_path " ]; then
184
- note_path=" $notes_dir /$note_path "
185
- fi
186
- if [ -z " $EDITOR " ]; then
187
- printf " Please set \$ EDITOR to edit notes\n"
188
- exit 1
189
- fi
190
- files+=(" ${note_path} " )
191
- done ; IFS=$OLDIFS
151
+ if [[ " $note_path " != * .$NOTES_EXT ]]; then
152
+ note_path=" $note_path .$NOTES_EXT "
153
+ fi
154
+ if [ ! -f " $note_path " ]; then
155
+ note_path=" $notes_dir /$note_path "
156
+ fi
157
+ if [ -z " $EDITOR " ]; then
158
+ printf " Please set \$ EDITOR to edit notes\n"
159
+ exit 1
160
+ fi
192
161
193
- $EDITOR " ${files[@]} " < /dev/tty
162
+ $EDITOR " $note_path " < /dev/tty
194
163
}
195
164
196
165
usage () {
197
- cat << EOF
166
+ cat << EOF
198
167
notes is a command line note taking tool.
199
168
200
169
Usage:
0 commit comments