Skip to content

Commit 3f2bee3

Browse files
committed
Clean up code
1 parent 74da090 commit 3f2bee3

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

notes

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,9 @@ remove_note() {
155155
open_something() {
156156
if [[ -p /dev/stdin ]]; then
157157
read -d $"\n" note_names
158-
local buffer=()
159-
while read note_name; do
158+
while read note_name; do
160159
buffer+="${note_name},"
161-
done <<< "$note_names"
160+
done <<< "$note_names"
162161
open_note ${buffer[@]}
163162
elif [ $# -gt 0 ]; then
164163
open_note "$*"
@@ -169,19 +168,15 @@ open_something() {
169168

170169
open_note() {
171170
local note_path
172-
local ext_check
173-
local buffer=$@
171+
local ext_check
172+
local buffer=$@
174173
local files=()
175174

176-
OLDIFS=$IFS
177-
IFS=','
178-
for arg in $buffer; do
179-
ext_check=true
180-
note_path="$arg"
181-
if echo $note_path | grep -q '\.[a-z]'; then
182-
ext_check=false
183-
fi
184-
if [[ "$note_path" != *$file_ext ]] && $ext_check; then
175+
OLDIFS=$IFS; IFS=','
176+
for file in $buffer; do
177+
note_path=$file
178+
ext_check=$(echo $note_path | grep -e '\.[a-z]')
179+
if [[ -z ${ext_check} ]]; then
185180
note_path="$note_path$file_ext"
186181
fi
187182
if [ ! -f "$note_path" ]; then
@@ -191,11 +186,10 @@ open_note() {
191186
printf "Please set \$EDITOR to edit notes\n"
192187
exit 1
193188
fi
194-
files+=(${note_path})
195-
done
196-
IFS=$OLDIFS
189+
files+=("${note_path}")
190+
done; IFS=$OLDIFS
197191

198-
$EDITOR ${files[@]} < /dev/tty
192+
$EDITOR "${files[@]}" < /dev/tty
199193
}
200194

201195
usage() {

0 commit comments

Comments
 (0)