From 4657adf4b1faf8887b358c45646ebf7472bdde73 Mon Sep 17 00:00:00 2001 From: Lucas Date: Mon, 25 May 2020 15:10:59 +0000 Subject: [PATCH] sekrit: bake in clipboard support with cp subcommand --- bin/sekrit.1 | 33 ++++++++++++++++++++++++--------- bin/sekrit.sh | 30 ++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 11 deletions(-) diff --git a/bin/sekrit.1 b/bin/sekrit.1 index 1632bf9..4b72b4c 100644 --- a/bin/sekrit.1 +++ b/bin/sekrit.1 @@ -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 .\" . .\" -.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 diff --git a/bin/sekrit.sh b/bin/sekrit.sh index 903ec1f..a607ab1 100644 --- a/bin/sekrit.sh +++ b/bin/sekrit.sh @@ -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 "$@" ;;