From c32b43e5c3ba25c711780db63fce4012dcea2e27 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 5 Feb 2016 22:26:25 +0100 Subject: show: allow selecting which clip line --- man/pass.1 | 6 +++--- src/password-store.sh | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/man/pass.1 b/man/pass.1 index 161350f..33b6036 100644 --- a/man/pass.1 +++ b/man/pass.1 @@ -86,10 +86,10 @@ List names of passwords inside the tree that match \fIpass-names\fP by using the .BR tree (1) program. This command is alternatively named \fBsearch\fP. .TP -\fBshow\fP [ \fI--clip\fP, \fI-c\fP ] \fIpass-name\fP +\fBshow\fP [ \fI--clip\fP[=\fIline-number\fP], \fI-c\fP[\fIline-number\fP] ] \fIpass-name\fP Decrypt and print a password named \fIpass-name\fP. If \fI--clip\fP or \fI-c\fP -is specified, do not print the password but instead copy the first line to the -clipboard using +is specified, do not print the password but instead copy the first (or otherwise specified) +line to the clipboard using .BR xclip (1) and then restore the clipboard after 45 (or \fIPASSWORD_STORE_CLIP_TIME\fP) seconds. .TP diff --git a/src/password-store.sh b/src/password-store.sh index 1425a59..9ea97ca 100755 --- a/src/password-store.sh +++ b/src/password-store.sh @@ -224,7 +224,7 @@ cmd_usage() { List passwords. $PROGRAM find pass-names... List passwords that match pass-names. - $PROGRAM [show] [--clip,-c] pass-name + $PROGRAM [show] [--clip[=line-number],-c[line-number]] pass-name Show existing password and optionally put it on the clipboard. If put on the clipboard, it will be cleared in $CLIP_TIME seconds. $PROGRAM grep search-string @@ -295,16 +295,16 @@ cmd_init() { } cmd_show() { - local opts clip=0 - opts="$($GETOPT -o c -l clip -n "$PROGRAM" -- "$@")" + local opts clip_location clip=0 + opts="$($GETOPT -o c:: -l clip:: -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" while true; do case $1 in - -c|--clip) clip=1; shift ;; + -c|--clip) clip=1; clip_location="${2:-1}"; shift 2 ;; --) shift; break ;; esac done - [[ $err -ne 0 ]] && die "Usage: $PROGRAM $COMMAND [--clip,-c] [pass-name]" + [[ $err -ne 0 ]] && die "Usage: $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]] [pass-name]" local path="$1" local passfile="$PREFIX/$path.gpg" @@ -313,7 +313,8 @@ cmd_show() { if [[ $clip -eq 0 ]]; then $GPG -d "${GPG_OPTS[@]}" "$passfile" || exit $? else - local pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | head -n 1)" + [[ $clip_location =~ ^[0-9]+$ ]] || die "Clip location '$clip_location' is not a number" + local pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | head -n $clip_location | tail -n 1)" [[ -n $pass ]] || exit 1 clip "$pass" "$path" fi -- cgit v1.2.3