Skip to content

Commit 1ca80ce

Browse files
committed
fix spaces on notes/notebook add insert rename import
1 parent 8d4ae43 commit 1ca80ce

File tree

2 files changed

+102
-29
lines changed

2 files changed

+102
-29
lines changed

notes

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ cmd_init (){ # setup directories and GPG key to be used
4242
echo Your default notebook $INITIAL_NOTEBOOK has been created you may now create notes
4343
# point to INITIAL_NOTEBOOK with DEFAULT_POINTER and USE_POINTER
4444
if [ ! -f "$DEFAULT_POINTER" ] ; then
45-
ln -s $INITIAL_NOTEBOOK $DEFAULT_POINTER
45+
ln -s "`basename $INITIAL_NOTEBOOK`" "$DEFAULT_POINTER"
4646
fi
4747
if [ ! -f "$USE_POINTER" ] ; then
48-
ln -s $INITIAL_NOTEBOOK $USE_POINTER
48+
ln -s "`basename $INITIAL_NOTEBOOK`" "$USE_POINTER"
4949
fi
5050
fi
5151
}
@@ -68,7 +68,7 @@ create_config () {
6868
echo You will need to edit the KEY parameter and set it to the email
6969
echo address of the key you wish to use
7070

71-
KEY="`gpg -K | grep uid | head -1 | sed 's/>$//; s/^.*<//'`"
71+
KEY="`gpg -K --with-colons | grep fpr | head -1 | tr -d 'fpr:::::::::' `"
7272
echo "KEY $KEY" > $CONFIGFILE
7373

7474
echo Default config written:
@@ -130,7 +130,8 @@ validate_gpg_keyid () {
130130
#
131131

132132
note_add () {
133-
notefile="$USE_POINTER/$@"
133+
filen="$@"
134+
notefile="${USE_POINTER}/`echo ${filen} | tr ' ' '_'`"
134135

135136
if [ -f "$notefile.gpg" ] ; then
136137
echo File exists ... cannot create
@@ -153,7 +154,9 @@ note_add () {
153154

154155
note_import () {
155156
toimport="$@"
157+
pathname="`dirname ${toimport}`"
156158
notefile="`basename ${toimport}`"
159+
notefile="`echo ${notefile} | tr ' ' '_'`"
157160

158161
get_recipient
159162

@@ -177,6 +180,7 @@ note_view () {
177180
}
178181

179182
note_edit () {
183+
myoptions="`echo ${theoptions} | tr ' ' '_'`"
180184
notefile="$USE_POINTER/$@"
181185
decrypted="`echo ${notefile} | sed s/.gpg//`"
182186

@@ -221,7 +225,7 @@ note_rename () {
221225
shift
222226
notefile="$USE_POINTER/$@"
223227
read -p "Please enter new name for note: " newname
224-
newname="${newname// /_}"
228+
newname="`echo ${newname} | tr ' ' '_'`"
225229

226230
case $notefile in
227231
*gpg) skip;;
@@ -255,7 +259,9 @@ note_rename () {
255259
#
256260

257261
notebook_add () {
258-
new_notebook="${NOTESDIR}/$@"
262+
notebookname="$@"
263+
new_notebook="${NOTESDIR}/`echo ${notebookname} | tr ' ' '_'`"
264+
259265
if [ ! -d "$new_notebook" ] ; then
260266
mkdir "$new_notebook"
261267
chmod 700 "$new_notebook"
@@ -272,7 +278,7 @@ notebook_delete () {
272278
exit 1
273279
else
274280
echo Deleting files from $notebook
275-
rm -i ${notebook}/*.gpg
281+
rm -if ${notebook}/*.gpg
276282

277283
if [ $? = 0 ] ; then
278284
rmdir "$notebook"
@@ -292,7 +298,7 @@ notebook_rename () {
292298

293299
notebook="$NOTESDIR/$@"
294300
read -p "Please enter new name for note: " newname
295-
newname="${newname// /_}"
301+
newname="`echo ${newname} | tr ' ' '_'`"
296302
newnotebook="${NOTESDIR}/${newname}"
297303

298304
case $MVCP in
@@ -389,19 +395,17 @@ cmd_find () {
389395
}
390396

391397
cmd_insert () {
392-
theoptions="$@"
393-
myoptions="`echo ${theoptions} | tr ' ' '_'`"
398+
myoptions="$@"
394399
case $PROGRAM in
395-
"notes") echo my options = ${myoptions} ; note_add $myoptions;;
400+
"notes") note_add $myoptions;;
396401
"notebook") notebook_add $myoptions;;
397402
esac
398403
}
399404

400405
cmd_import () {
401-
theoptions="$@"
402-
myoptions="${theoptions// /_}"
406+
myoptions="$@"
403407
case $PROGRAM in
404-
"notes") echo my options = ${myoptions} ; note_import $myoptions;;
408+
"notes") note_import $myoptions;;
405409
"notebook") cmd_usage;;
406410
esac
407411
}
@@ -413,25 +417,24 @@ cmd_generate () {
413417
cmd_delete () {
414418
myoptions="$@"
415419
case $PROGRAM in
416-
"notes") echo my options = ${myoptions} ; note_delete $myoptions;;
420+
"notes") note_delete $myoptions;;
417421
"notebook") notebook_delete $myoptions;;
418422
esac
419423
}
420424

421425
cmd_edit () {
422426
myoptions="$@"
423427
case $PROGRAM in
424-
"notes") echo my options = ${myoptions} ; note_edit $myoptions;;
425-
"notebook") notebook_edit $myoptions;;
428+
"notes") note_edit $myoptions;;
429+
"notebook") notebook_edit ${myoptions};;
426430
esac
427431
}
428432

429433
cmd_copy_move () {
430-
theoptions="$@"
431-
myoptions="${theoptions// /_}"
434+
myoptions="$@"
432435
case $PROGRAM in
433-
"notes") echo my options = ${myoptions} ; note_rename $myoptions;;
434-
"notebook") notebook_rename $myoptions;;
436+
"notes") note_rename $myoptions;;
437+
"notebook") notebook_rename ${myoptions};;
435438
esac
436439
}
437440

@@ -444,11 +447,8 @@ cmd_git () {
444447
}
445448

446449
cmd_default () {
447-
echo set default notebook
448450
nb="$@"
449451
notebook="$NOTESDIR/$nb"
450-
echo nb = $nb
451-
echo notebook = $notebook
452452

453453
if [ "$nb" = "" ] ;then
454454
echo Default notebook = "`readlink -f $DEFAULT_POINTER`"
@@ -470,10 +470,9 @@ cmd_use () {
470470
if [ "$nb" = "" ] ;then
471471
defaultnbval="`readlink -f $DEFAULT_POINTER`"
472472
defaultnb="`basename $DEFAULT_POINTER`"
473-
echo no notebook specified use default
473+
echo no notebook specified using default notebook
474474
unlink "$USE_POINTER"
475475
ln -s "`basename $defaultnbval`" "$USE_POINTER"
476-
#ln -s "`$defaultnbval`" "$USE_POINTER"
477476
exit 0
478477
fi
479478
if [ -d "$notebook" ] ; then
@@ -488,6 +487,13 @@ cmd_use () {
488487
cmd_newkey () {
489488
mynewkey="$1"
490489

490+
if [ "$mynewkey" = "" ]; then
491+
echo No new key supplied
492+
echo There are the following private keys on your keyring
493+
gpg --list-secret-keys --with-colons --keyid-format short | grep sec | cut -d':' -f 5
494+
exit 1
495+
fi
496+
491497
get_recipient
492498
get_gpg_keyid $mynewkey
493499

@@ -502,9 +508,8 @@ cmd_newkey () {
502508

503509
done
504510

505-
# need to fix up config file now ...
506-
NEWUSER="`gpg -k ${mynewkey} | grep uid | head -1 | sed 's/>$//; s/^.*<//' `"
507-
sed -i s/^KEY.*$/KEY\\t${NEWUSER}/ ${CONFIGFILE}
511+
# replace key in config file
512+
sed -i s/^KEY.*$/KEY\\t${mynewkey}/ ${CONFIGFILE}
508513
}
509514

510515

notes.1

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.\" Manpage for Standard (?) Unix Notes
2+
.\" aka notes
3+
.\" See https://github.com/Standard-Unix-Notes/unix-notes
4+
.TH man 1 "10 June 2021" "1.0" "notes man page"
5+
.SH NAME
6+
notes \- maintain GPG encrypted notes
7+
.SH SYNOPSIS
8+
notes [command] [filename | note title]
9+
10+
.SH CONFIGURATION
11+
Manual configuration for the GPG key can be added using the phrase
12+
KEY <email address>
13+
in the file <notesdir>/config
14+
.SH DESCRIPTION
15+
The Standard(?) Unix Notes notebook system is a GPG encrypted 'notebook' where each note is individually encrypted into a notebook folder. It can handle multiple notebook folders and can decrypt/re-encrypt for a new GPG key easily. The program is based upon Password-Store the standard Unix password manager of which it borrows some code.
16+
.SH COMMANDS
17+
The notes program takes a set of commands which allows the user to manipulate the encrypted notes in the system.
18+
.SH COMMANDS
19+
init initialize notes system
20+
newkey change GPG key
21+
help show help
22+
version show version
23+
show|ls|list list notes in current notebook
24+
newkey email change GPG key
25+
26+
find|search find notes [YET TO BE IMPLEMENTED]
27+
insert|add note_title add a note
28+
view|cat note_title view a note
29+
import file import a text file as a note
30+
rename|mv note_title rename a note (will prompt for new name)
31+
copy|cp note_title copy a note (will prompt for new name)
32+
delete|rm note_title delete a note
33+
edit|ed note_title edit a note
34+
35+
36+
37+
38+
.SH OPTIONS [Normally only in Sections 1, 8]
39+
Most commands take either a <note title>, filename or a GPG key ID. See the individual COMMANDS for details on which options each command takes.
40+
The notes and notebook commands strip spaces from note filenames and notebook directory names. It replaces them with underscores. This behaviour occurs even if the user encloses the filename with spaces in quotes because there are other issues that occur when handling notes with spaces in - particularly when replacing the encryption key.
41+
.SH EXIT STATUS
42+
Upon an error notes returns a non zero value upon aborting.
43+
.SH ENVIRONMENT
44+
$EDITOR Notes uses the shell variable to determine which editor the user prefers. If unset it will default to 'vi'
45+
46+
By default notes creates it's notes directory in ~/.notes for the user. This can be changed by midifying the shell script.
47+
.SH FILES
48+
The following files are found in the notes directory (~/.notes by default):
49+
50+
config The configuration file for notes. Currently the only option is for specifying the key to be used for encryption (KEY <email address>)
51+
DEFAULT This link points to the default notebook (notes). This can be reassigned by using the command 'notebook default <notebook name>'
52+
USE This link points to the currently used notebook. It can be changed by issuing the command 'notebook use <notebook name>'. You can also set this to the default notebook by omitting the notebook name parameter.
53+
.SH VERSIONS [Normally only in Sections 2, 3]
54+
55+
.SH CONFORMING TO
56+
The script is written to use the Bourne Shell and avoid all Bash-isms (which would have made the coding a little easier in some cases. Although Bash is installed by default on most Linuxes, it is not installed by default on a number of other Unix-like operating systems including FreeBSD.
57+
58+
This is deliberate as all Unix and Linux systems should have a POSIX compliant shell (or at least be backwards compatible to one). Hence the application was written for the lowest common denominator.
59+
.SH NOTES
60+
There is currently no sync built into this application. However, the user can simply run a rsync or scp in order to synchronize between two machines running Notes.
61+
.SH BUGS
62+
See https://github.com/Standard-Unix-Notes/unix-notes/issues for details on any Bugs and Issues with the project.
63+
64+
Please report any bugs on the GitHub page.
65+
.SH EXAMPLES
66+
67+
.SH SEE ALSO
68+
notebook The companion command for managing notebooks for notes. See notebook(1) for details.

0 commit comments

Comments
 (0)