m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-02-05 22:26:25 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-02-05 22:26:25 +0100
commitc32b43e5c3ba25c711780db63fce4012dcea2e27 (patch)
tree8a4b98f3354da7bd8a7bef702c28e1c91de17106
parent9715ddcd2b2a3f3ed0f27398048191ac2de60c8b (diff)
show: allow selecting which clip line
-rw-r--r--man/pass.16
-rwxr-xr-xsrc/password-store.sh13
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