sekrit: add rm command

While at it, fix a typo.
This commit is contained in:
Lucas 2020-12-03 00:18:11 +00:00
parent 19631627d6
commit e71a6eb321
2 changed files with 39 additions and 2 deletions

View File

@ -38,6 +38,11 @@
.Nm
.Cm ls
.Op Ar keys ...
.Nm
.Cm rm
.Op Fl f
.Ar key
.Op Ar key ...
.Sh DESCRIPTION
.Nm
is a small shell script for managing encrypted files.
@ -104,7 +109,13 @@ given as argument,
list all the registered keys under that hierarchy.
If no
.Ar key
is given, list all the registeres keys.
is given, list all the registered keys.
.It Nm Cm rm Oo Fl f Oc Ar key Op Ar key ...
Removes the file associated with each
.Ar key .
Asks for confirmation before removing each file, unless
.Fl f
is given.
.El
.Sh ENVIRONMENT
.Bl -tag -width SEKRIT_GPG_ID

View File

@ -35,6 +35,7 @@ Usage:
${0##*/} get key
${0##*/} has key
${0##*/} ls [keys ...]
${0##*/} rm [-f] key [key ...]
If no value was provided on command line, add reads from stdin.
.
@ -116,8 +117,8 @@ sekrit_cp()
sekrit_gen()
{
len=43
OPTIND=1
len=43
while getopts l: flag; do
case "$flag" in
l) len=$(to_number "$OPTARG") ||
@ -179,6 +180,30 @@ sekrit_ls()
fi
}
sekrit_rm()
{
OPTIND=1
fflag=
while getopts f flag; do
case "$flag" in
f) fflag=-f ;;
*) usage ;;
esac
done
shift $((OPTIND - 1))
[ $# -ge 1 ] || usage
for key; do
path=$(make_key_path "$key")
if [ ! -f "$path" ]; then
printf "%s: no data for key %s\n" "${0##*/}" "$key" >&2
else
rm -i $fflag "$path"
fi
done
}
set -e
[ $# -ge 1 ] || usage
@ -198,5 +223,6 @@ gen) sekrit_gen "$@" ;;
get) sekrit_get "$@" ;;
has) sekrit_has "$@" ;;
ls) sekrit_ls "$@" ;;
rm) sekrit_rm "$@" ;;
*) usage ;;
esac