sekrit: bake in clipboard support with cp subcommand

This commit is contained in:
Lucas 2020-05-25 15:10:59 +00:00
parent 540f26be40
commit 4657adf4b1
2 changed files with 52 additions and 11 deletions

View File

@ -1,6 +1,6 @@
.\"
.\" sekrit.1
.\" Written in 2018 by Lucas
.\" Written in 2018,2020 by Lucas
.\" CC0 1.0 Universal/Public domain - No rights reserved
.\"
.\" To the extent possible under law, the author(s) have dedicated all
@ -10,28 +10,32 @@
.\" Dedication along with this software. If not, see
.\" <http://creativecommons.org/publicdomain/zero/1.0/>.
.\"
.Dd September 25, 2018
.Dd May 25, 2020
.Dt SEKRIT 1
.Os
.Sh NAME
.Nm sekrit
.Nd Secret files manager
.Sh SYNOPSIS
.Nm sekrit
.Nm
.Cm add
.Ar key
.Op Ar value ...
.Nm sekrit
.Nm
.Cm cp
.Op Fl k
.Op key
.Nm
.Cm gen
.Op Fl l Ar length
.Op Ar chars
.Nm sekrit
.Nm
.Cm get
.Ar key
.Nm sekrit
.Nm
.Cm has
.Ar key
.Nm sekrit
.Nm
.Cm ls
.Op Ar keys ...
.Sh DESCRIPTION
@ -61,6 +65,14 @@ will read the value from standard input.
will fail if
.Ar key
already has a value.
.It Nm Cm cp Oo Fl k Oc Ar key
Decrypts the value associated with
.Ar key
and copies it to the clipboard with
.Xr xclip 1 .
It removes the last newline unless
.Fl k
is given.
.It Nm Cm gen Oo Fl l Ar length Oc Op Ar chars
Outputs a randomly generated sequence.
The generated sequence consist of characters
@ -122,9 +134,12 @@ in
.Ar example.com
you can run
.Bd -literal -offset indent
sekrit get accounts/example.com/user | xclip -l 1 -sel clip -q
sekrit get accounts/example.com/pass | xclip -l 1 -sel clip -q
sekrit cp accounts/example.com/user
sekrit cp accounts/example.com/pass
.Ed
.Sh SEE ALSO
.Xr gpg2 1 ,
.Xr xclip 1
.Sh AUTHORS
.An Lucas
.Sh LICENSE

View File

@ -30,6 +30,7 @@ usage()
cat - <<. >&2
Usage:
${0##*/} add key [value ...]
${0##*/} cp [-k] key
${0##*/} gen [-l length] [chars]
${0##*/} get key
${0##*/} has key
@ -82,6 +83,30 @@ sekrit_add()
chmod -- 400 "$f"
}
sekrit_cp()
{
command -v xclip >/dev/null 2>&1 ||
err "xclip required for clipboard support"
OPTIND=1
rmlastnl=-rmlastnl
while getopts k flag; do
case "$flag" in
k) rmlastnl=
;;
*) usage
;;
esac
done
shift $((OPTIND - 1))
[ $# -eq 1 ] || usage
key=$1
sekrit_get "$key" |
xclip $rmlastnl -loops 1 -quiet -selection clip 2>/dev/null
}
sekrit_gen()
{
len=43
@ -113,7 +138,7 @@ sekrit_get()
{
[ $# -eq 1 ] || usage
key=$1
check_key "$1"
check_key "$key"
shift
f=$SEKRIT_DIR/$key.gpg
@ -125,7 +150,7 @@ sekrit_has()
{
[ $# -eq 1 ] || usage
key=$1
check_key "$1"
check_key "$key"
shift
[ -f "$SEKRIT_DIR/$key.gpg" ]
@ -164,6 +189,7 @@ mkdir -p "$SEKRIT_DIR"
case "$cmd" in
add) sekrit_add "$@" ;;
cp) sekrit_cp "$@" ;;
gen) sekrit_gen "$@" ;;
get) sekrit_get "$@" ;;
has) sekrit_has "$@" ;;