Skip to content

Commit 28465e9

Browse files
committed
added notebook use functionality
1 parent 3f604ef commit 28465e9

File tree

1 file changed

+65
-46
lines changed

1 file changed

+65
-46
lines changed

notes

Lines changed: 65 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/sh -x
22
#
33
# STANDARD(?) UNIX NOTES
44
#
@@ -23,30 +23,24 @@ GPG="gpg"
2323

2424
cmd_init (){ # setup directories and GPG key to be used
2525

26-
# set umask to this user only
2726
umask "${NOTES_UMASK:-077}"
2827

29-
# make notes directory
3028
if [ ! -d "$NOTESDIR" ]; then
3129
echo Creating notes directory: $NOTESDIR
3230
mkdir $NOTESDIR
3331
fi
3432

3533
create_config
3634

37-
# make default notebook
3835
echo making default notebook \'${DEFAULT_NOTEBOOK}\'
3936
if [ ! -d "$DEFAULT_NOTEBOOK" ]; then
4037
mkdir $DEFAULT_NOTEBOOK
4138
echo Your default notebook $DEFAULT_NOTEBOOK has been created you may now create notes
42-
39+
# point to DEFAULT_NOTEBOOK with DEFAULT_POINTER and USE_POINTER
4340
if [ ! -f "$DEFAULT_POINTER" ] ; then
44-
# point to DEFAULT_NOTEBOOK
4541
ln -s $DEFAULT_NOTEBOOK $DEFAULT_POINTER
4642
fi
47-
4843
if [ ! -f "$USE_POINTER" ] ; then
49-
# point to DEFAULT_NOTEBOOK
5044
ln -s $DEFAULT_NOTEBOOK $USE_POINTER
5145
fi
5246
fi
@@ -59,7 +53,7 @@ create_config () {
5953
echo You have the following private keys on your keyring
6054
gpg -K
6155

62-
echo By DEFAULT I will use the first key found as the key for encrypting
56+
echo By DEFAULT we will use the first key found as the key for encrypting
6357
echo If this is NOT what is required please edit $NOTESDIR/config to
6458
echo reflect the recipient you wish to use
6559
echo You will need to edit the KEY parameter and set it to the email
@@ -72,15 +66,15 @@ create_config () {
7266
cat $NOTESDIR/config
7367
}
7468

75-
get_recipient() {
69+
get_recipient () {
7670
KEY=`grep KEY $NOTESDIR/config | sed s/^KEY// | tr -d [:blank:]`
7771
}
7872

7973
#
8074
# note functions
8175
#
8276

83-
note-add() {
77+
note_add () {
8478
notefile="$USE_POINTER/$@"
8579

8680
if [ -f "$notefile.gpg" ] ; then
@@ -93,18 +87,16 @@ note-add() {
9387
# create temporary note file
9488
$EDITOR "$notefile"
9589

96-
# spell check
9790
#aspell -c "$notefile"
9891

9992
# encrypt note file
10093
$GPG -e -r $KEY $GPG_OPTS "$notefile"
10194

102-
# delete temporary note file now that ${notefile}.gpgs now created
10395
rm "$notefile"
10496
fi
10597
}
10698

107-
note-import() {
99+
note_import () {
108100
toimport="$@"
109101
notefile="`basename ${toimport}`"
110102

@@ -115,7 +107,7 @@ note-import() {
115107
fi
116108
}
117109

118-
note-view() {
110+
note_view () {
119111
notefile="$USE_POINTER/$@"
120112

121113
get_recipient
@@ -129,7 +121,7 @@ note-view() {
129121
fi
130122
}
131123

132-
note-edit() {
124+
note_edit () {
133125
notefile="$USE_POINTER/$@"
134126
decrypted="`echo ${notefile} | sed s/.gpg//`"
135127

@@ -153,11 +145,11 @@ note-edit() {
153145
fi
154146
}
155147

156-
note-list() {
148+
note_list () {
157149
ls "${USE_POINTER}" | column | more
158150
}
159151

160-
note-delete() {
152+
note_delete () {
161153
notefile="$USE_POINTER/$@"
162154

163155
if [ -f "$notefile" ]; then
@@ -169,7 +161,7 @@ note-delete() {
169161
fi
170162
}
171163

172-
note-rename() {
164+
note_rename () {
173165
MVCP="$1"
174166
shift
175167
notefile="$USE_POINTER/$@"
@@ -206,7 +198,7 @@ note-rename() {
206198
# notebook functions
207199
#
208200

209-
notebook-add() {
201+
notebook_add () {
210202
new_notebook="${NOTESDIR}/$@"
211203
if [ ! -d "$new_notebook" ] ; then
212204
mkdir "$new_notebook"
@@ -217,7 +209,7 @@ notebook-add() {
217209
fi
218210
}
219211

220-
notebook-delete() {
212+
notebook_delete () {
221213
notebook="${NOTESDIR}/$@"
222214
if [ ! -d "${notebook}" ] ; then
223215
echo Error: Notebook \'$notebook\' does not exist
@@ -234,7 +226,7 @@ notebook-delete() {
234226
fi
235227
}
236228

237-
notebook-rename() {
229+
notebook_rename () {
238230
MVCP="$1"
239231
shift
240232

@@ -259,7 +251,7 @@ notebook-rename() {
259251
fi
260252
}
261253

262-
notebook-list () {
254+
notebook_list () {
263255
ls "${NOTESDIR}" | sed 's/DEFAULT//; s/USE//; s/config//' | column | more
264256
}
265257

@@ -280,27 +272,25 @@ GPG encrypted notes system for BSD and Linux systems
280272
281273
SYSTEM:
282274
283-
notes init initialize notes system
275+
notes init initialize notes system
284276
notes newkey change GPG key
285-
notes help show help
277+
notes help show help
286278
notes version show version
287279
notes show|ls|list list notes in current notebook
288280
289-
290281
NOTES MANAGEMENT:
291282
292-
notes find|search find notes
283+
notes find|search find notes [YET TO BE IMPLMENTED]
293284
notes insert|add note_title add a note
294285
notes import file import a text file as a note
295286
notes rename|mv note_title rename a note (will prompt for new name)
296287
notes copy|cp note_title copy a note (will prompt for new name)
297288
notes delete|rm note_title delete a note
298289
notes edit|ed note_title edit a note
299290
300-
301291
NOTEBOOK MANAGEMENT:
302292
303-
notebook list|ls list notebooks
293+
notebook list|ls list notebooks
304294
notebook default notebook change default notebook
305295
notebook use notebook use a notebook
306296
notebook add|insert notebook add a notebook
@@ -322,16 +312,16 @@ cmd_view () {
322312
exit 1
323313
fi
324314
case $PROGRAM in
325-
"notes") note-view $myoptions;;
315+
"notes") note_view $myoptions;;
326316
"notebook") cmd_usage;;
327317
esac
328318
}
329319

330320
cmd_show () {
331321
myoptions="$@"
332322
case $PROGRAM in
333-
"notes") note-list $myoptions;;
334-
"notebook") notebook-list $myoptions;;
323+
"notes") note_list $myoptions;;
324+
"notebook") notebook_list $myoptions;;
335325
esac
336326
}
337327

@@ -342,44 +332,44 @@ cmd_find () {
342332
cmd_insert () {
343333
myoptions="$@"
344334
case $PROGRAM in
345-
"notes") echo my options = ${myoptions} ; note-add $myoptions;;
346-
"notebook") notebook-add $myoptions;;
335+
"notes") echo my options = ${myoptions} ; note_add $myoptions;;
336+
"notebook") notebook_add $myoptions;;
347337
esac
348338
}
349339

350340
cmd_import () {
351341
myoptions="$@"
352342
case $PROGRAM in
353-
"notes") echo my options = ${myoptions} ; note-import $myoptions;;
343+
"notes") echo my options = ${myoptions} ; note_import $myoptions;;
354344
"notebook") cmd_usage;;
355345
esac
356346
}
357347

358348
cmd_generate () {
359-
echo cmd_generate
349+
echo cmd_generate not implmented yet
360350
}
361351

362352
cmd_delete () {
363353
myoptions="$@"
364354
case $PROGRAM in
365-
"notes") echo my options = ${myoptions} ; note-delete $myoptions;;
366-
"notebook") notebook-delete $myoptions;;
355+
"notes") echo my options = ${myoptions} ; note_delete $myoptions;;
356+
"notebook") notebook_delete $myoptions;;
367357
esac
368358
}
369359

370360
cmd_edit () {
371361
myoptions="$@"
372362
case $PROGRAM in
373-
"notes") echo my options = ${myoptions} ; note-edit $myoptions;;
374-
"notebook") notebook-edit $myoptions;;
363+
"notes") echo my options = ${myoptions} ; note_edit $myoptions;;
364+
"notebook") notebook_edit $myoptions;;
375365
esac
376366
}
377367

378368
cmd_copy_move () {
379369
myoptions="$@"
380370
case $PROGRAM in
381-
"notes") echo my options = ${myoptions} ; note-rename $myoptions;;
382-
"notebook") notebook-rename $myoptions;;
371+
"notes") echo my options = ${myoptions} ; note_rename $myoptions;;
372+
"notebook") notebook_rename $myoptions;;
383373
esac
384374
}
385375

@@ -391,26 +381,55 @@ cmd_git () {
391381
echo git not implemented yet
392382
}
393383

384+
cmd_default () {
385+
echo set default notebook
386+
notebook="$NOTESDIR/$@"
387+
388+
if [ -d "$notebook" ] ; then
389+
echo target notebook exists
390+
else
391+
echo Cannot set default notebook to $notebook as it does not exist
392+
fi
393+
}
394+
395+
cmd_use () {
396+
echo use notebook
397+
nb="$@"
398+
notebook="$NOTESDIR/$nb"
399+
echo nb = $nb
400+
echo notebook = $notebook
401+
402+
if [ -d "$notebook" ] ; then
403+
echo target notebook exists
404+
unlink "$NOTESDIR/USE"
405+
ln -sf "$notebook" "$NOTESDIR/USE"
406+
else
407+
echo Cannot use $notebook as $nb does not exist
408+
fi
409+
}
410+
394411
cmd_newkey () {
395412
echo newkey
396413
}
397414

398415
#########################
399-
# #
400-
# MAIN PROGRAM #
401-
# #
416+
# #
417+
# MAIN PROGRAM #
418+
# #
402419
#########################
403420

404421
PROGRAM="${0##*/}"
405422
COMMAND="$1"
406423

407424
case "$1" in
408425
init) shift; cmd_init "$@" ;;
426+
default) shift; cmd_default "$@" ;;
427+
use) shift; cmd_use "$@" ;;
409428
newkey) shift; cmd_newkey "$@" ;;
410429
help|--help) shift; cmd_usage "$@" ;;
411430
version|--version) shift; cmd_version "$@" ;;
412431
show|ls|list) shift; cmd_show "$@" ;;
413-
view) shift; cmd_view "$@" ;;
432+
view) shift; cmd_view "$@" ;;
414433
find|search) shift; cmd_find "$@" ;;
415434
grep) shift; cmd_grep "$@" ;;
416435
insert|add) shift; cmd_insert "$@" ;;

0 commit comments

Comments
 (0)