This is basically just a copy of the `cmd_show()` command except,
instead of
outputting the password string or using `xclip` to copy it to the
clipboard,
this uses `qrencode` to output a QR-code of the password.
I decided I wanted this functionality for myself, but I definitely
understand
if you're hesitant to merge it since it would add another dependency -
qrencode
- to the project.
The command - `pass qr` - can take an optional type flag in either short
(-t
TYPE) or long (--type=TYPE) format, which is used directly with
`qrencode` to
determine how the QR-code is output. I've set the default to `UTF8`
instead of
letting qrencode default to `PNG` because `UTF8` outputs to stdout and I
assume
most `pass` users want to stay in a terminal as much as possible.
I've never submitted a patch through a mailing list before, so I hope
I'm doing
this correctly.
Also, thank you for an amazing piece of software.
Password store really saved me from the clutches of KeePass's GUI and
bloat.
Best regards,
ahstro
From 03da808656a0d8969b5fc1f43f79fc220cf0bd4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anton=20Str=C3=B6mkvist?= <[email protected]>
Date: Fri, 29 Jan 2016 11:08:29 +0100
Subject: [PATCH] Add QR command
Add a command that uses qrencode to generate a QR-code of the password
in one of several different formats.
---
man/pass.1 | 9 +++++++++
src/password-store.sh | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/man/pass.1 b/man/pass.1
index e1fe605..58f974e 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -93,6 +93,15 @@ clipboard using
.BR xclip (1)
and then restore the clipboard after 45 (or \fIPASSWORD_STORE_CLIP_TIME\fP) seconds.
.TP
+\fBqr\fP [ \fI--type=TYPE\fP, \fI-t TYPE\fP ] \fIpass-name\fP
+Decrypt a password named \fIpass-name\fP and encode it as a QR-code using
+.BR qrencode (1).
+If a \fITYPE\fP is specified, the output will be of that type, otherwise it will
+default to UTF8.
+See
+.BR qrencode (1)
+for available \fITYPE\fPs.
+.TP
\fBinsert\fP [ \fI--echo\fP, \fI-e\fP | \fI--multiline\fP, \fI-m\fP ] [ \fI--force\fP, \fI-f\fP ] \fIpass-name\fP
Insert a new password into the password store called \fIpass-name\fP. This will
read the new password from standard in. If \fI--echo\fP or \fI-e\fP is \fInot\fP specified,
diff --git a/src/password-store.sh b/src/password-store.sh
index d535a74..4391527 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -330,6 +330,39 @@ cmd_show() {
fi
}
+cmd_qr() {
+ local opts type="UTF8"
+ opts="$($GETOPT -o t: -l type: -n "$PROGRAM" -- "$@")"
+ local err=$?
+ eval set -- "$opts"
+ while true; do case $1 in
+ -t|--type) type="$2"; shift 2 ;;
+ --) shift; break ;;
+ esac done
+
+ [[ $err -ne 0 ]] && die "Usage: $PROGRAM $COMMAND [--type=outputtype,-t outputtype] [pass-name]"
+
+ local path="$1"
+ local passfile="$PREFIX/$path.gpg"
+ check_sneaky_paths "$path"
+ if [[ -f $passfile ]]; then
+ local pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | head -n 1)"
+ [[ -n $pass ]] || exit 1
+ qrencode -t "$type" "$pass"
+ elif [[ -d $PREFIX/$path ]]; then
+ if [[ -z $path ]]; then
+ echo "Password Store"
+ else
+ echo "${path%\/}"
+ fi
+ tree -C -l --noreport "$PREFIX/$path" | tail -n +2 | sed -E 's/\.gpg(\x1B\[[0-9]+m)?( ->|$)/\1\2/g' # remove .gpg at end of line, but keep colors
+ elif [[ -z $path ]]; then
+ die "Error: password store is empty. Try \"pass init\"."
+ else
+ die "Error: $path is not in the password store."
+ fi
+}
+
cmd_find() {
[[ -z "$@" ]] && die "Usage: $PROGRAM $COMMAND pass-names..."
IFS="," eval 'echo "Search Terms: $*"'
@@ -581,6 +614,7 @@ case "$1" in
help|--help) shift; cmd_usage "$@" ;;
version|--version) shift; cmd_version "$@" ;;
show|ls|list) shift; cmd_show "$@" ;;
+ qr) shift; cmd_qr "$@" ;;
find|search) shift; cmd_find "$@" ;;
grep) shift; cmd_grep "$@" ;;
insert|add) shift; cmd_insert "$@" ;;
--
2.7.0
_______________________________________________
Password-Store mailing list
[email protected]
http://lists.zx2c4.com/mailman/listinfo/password-store