commit 37b682e691444527b6a0c727dfca70d989b3779a
parent f57477daf48dae78ca68eda3e2fdb24f9b16ef57
Author: Ed van Bruggen <edvb54@gmail.com>
Date: Sun, 19 Mar 2017 20:53:59 -0700
Add -D option to delete all notes
Also Update README and man page with option. Improve man page looks.
Diffstat:
README.md | | | 28 | +++++++++++++++++++--------- |
nt.1 | | | 42 | +++++++++++++++++++++++++++++++----------- |
nt.c | | | 21 | +++++++++++++++++++-- |
3 files changed, 69 insertions(+), 22 deletions(-)
diff --git a/README.md b/README.md
@@ -2,7 +2,7 @@
## SYNOPSIS
-`nt` [-lvy] [-f *FILE*] [-e *NOTE*] [-d *NOTE*] [-s *SEARCH*] [-n *NUM* | -*NUM*] [*NOTE* ...]
+`nt` [**-Dlvy**] [**-f** *FILE*] [**-e** *NOTE*] [**-d** *NOTE*] [**-s** *SEARCH*] [**-n** *NUM* | **-NUM**] [*NOTE* ...]
## DESCRIPTION
@@ -10,28 +10,31 @@ Simple note taker for the command line.
## OPTIONS
--d *NOTE*
+**-d** *NOTE*
Delete *NOTE* from notes
--e *NOTE*
+**-D**
+ Delete all notes from *FILE*
+
+**-e** *NOTE*
Edit *NOTE* with new text given through stdin
--f *FILE*
+**-f** *FILE*
Load *FILE* instead of default one
--l
+**-l**
List notes
--n *NUM*, -*NUM*
+**-n** *NUM*, **-NUM**
List last *NUM* notes
--s *SEARCH*
+**-s** *SEARCH*
Search for pattern *SEARCH* in notes
--v
+**-v**
Print version info and exit
--y
+**-y**
Auto reply yes to confirmation prompts
## USAGE
@@ -98,6 +101,13 @@ Edit note with new text given from stdin:
wash car
eat pie
+Remove all notes:
+
+ $ nt -yD
+ $ nt -l
+ $ nt -f list -yD
+ $ nt -f list -l
+
## AUTHOR
Ed van Bruggen <edvb54@gmail.com>
diff --git a/nt.1 b/nt.1
@@ -4,29 +4,38 @@
nt \- simple note taker
.SH SYNOPSIS
.PP
-\fB\fCnt\fR [\-lv] [\-f \fIFILE\fP] [\-e \fINOTE\fP] [\-d \fINOTE\fP] [\-s \fISEARCH\fP] [\-n \fINUM\fP | \-\fINUM\fP] [\fINOTE\fP ...]
+\fB\fCnt\fR [\fB\-Dlvy\fP] [\fB\-f\fP \fIFILE\fP] [\fB\-e\fP \fINOTE\fP] [\fB\-d\fP \fINOTE\fP] [\fB\-s\fP \fISEARCH\fP] [\fB\-n\fP \fINUM\fP | \fB\-NUM\fP] [\fINOTE\fP ...]
.SH DESCRIPTION
.PP
Simple note taker for the command line.
.SH OPTIONS
.PP
-\-v
- Print version info and exit
+\fB\-d\fP \fINOTE\fP
+ Delete \fINOTE\fP from notes
+.PP
+\fB\-D\fP
+ Delete all notes from \fIFILE\fP
+.PP
+\fB\-e\fP \fINOTE\fP
+ Edit \fINOTE\fP with new text given through stdin
.PP
-\-f \fIFILE\fP
+\fB\-f\fP \fIFILE\fP
Load \fIFILE\fP instead of default one
.PP
-\-l
+\fB\-l\fP
List notes
.PP
-\-n \fINUM\fP
+\fB\-n\fP \fINUM\fP, \fB\-NUM\fP
List last \fINUM\fP notes
.PP
-\-s \fISEARCH\fP
- Search for \fISEARCH\fP in notes
+\fB\-s\fP \fISEARCH\fP
+ Search for pattern \fISEARCH\fP in notes
.PP
-\-d \fINOTE\fP
- Delete \fINOTE\fP from notes
+\fB\-v\fP
+ Print version info and exit
+.PP
+\fB\-y\fP
+ Auto reply yes to confirmation prompts
.SH USAGE
.PP
Add simple note and list it:
@@ -99,7 +108,7 @@ Remove given note:
.PP
.RS
.nf
-$ nt \-d buy pie
+$ nt \-yd buy pie
$ nt \-l
clean dishes
wash car
@@ -118,6 +127,17 @@ wash car
eat pie
.fi
.RE
+.PP
+Remove all notes:
+.PP
+.RS
+.nf
+$ nt \-yD
+$ nt \-l
+$ nt \-f list \-yD
+$ nt \-f list \-l
+.fi
+.RE
.SH AUTHOR
.PP
Ed van Bruggen
diff --git a/nt.c b/nt.c
@@ -93,6 +93,18 @@ nt_add(char *str)
}
+/* delete all notes from fname */
+void
+nt_del_all(void)
+{
+ Note *cur = head;
+ if (confirm("delete all notes in '%s'", fname)) {
+ for (; cur; cur = cur->next)
+ cur->str = NULL;
+ remove(fname);
+ }
+}
+
/* delete oldest matching note from notes */
void
nt_del(void)
@@ -119,7 +131,6 @@ nt_del(void)
die("%s: delete: '%s' not found", argv0, sub);
}
-
void
nt_edit()
{
@@ -182,6 +193,9 @@ run(void)
case 'd':
nt_del();
break;
+ case 'D':
+ nt_del_all();
+ break;
case 'e':
nt_edit();
break;
@@ -244,7 +258,7 @@ cleanup(void)
void
usage(void)
{
- die("usage: %s [-lvy] [-f FILE] [-e NOTE] [-d NOTE]\n"
+ die("usage: %s [-Dlvy] [-f FILE] [-e NOTE] [-d NOTE]\n"
" [-s SEARCH] [-n NUM | -NUM] [NOTE ...]", argv0);
}
@@ -255,6 +269,9 @@ main(int argc, char *argv[])
case 'd':
mode = 'd';
break;
+ case 'D':
+ mode = 'D';
+ break;
case 'e':
mode = 'e';
break;