summaryrefslogtreecommitdiff
path: root/src
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 /src
parent9715ddcd2b2a3f3ed0f27398048191ac2de60c8b (diff)
downloadpass-c32b43e5c3ba25c711780db63fce4012dcea2e27.tar.gz
pass-c32b43e5c3ba25c711780db63fce4012dcea2e27.tar.bz2
pass-c32b43e5c3ba25c711780db63fce4012dcea2e27.zip
show: allow selecting which clip line
Diffstat (limited to '')
-rwxr-xr-xsrc/password-store.sh13
1 files changed, 7 insertions, 6 deletions
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