[pass] [PATCH] Added functionality to retrieve username from a password file and copy to clipboard.
ged
ged at qube.io
Sun Oct 7 21:35:35 CEST 2012
This requires a multiline password file with a line for the user as follows:
user: FredFlintstone
Case is ignored. Field seperator is ": " and everything after the field seperator is treated as the username.
Files modified are src/password-store.sh and man/pass.1.
---
man/pass.1 | 16 +++++++++++++++-
src/password-store.sh | 21 ++++++++++++++++-----
2 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/man/pass.1 b/man/pass.1
index b8bb08c..c205c81 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -68,12 +68,14 @@ by using the
.BR tree (1)
program. This command is alternatively named \fBlist\fP.
.TP
-\fBshow\fP [ \fI--clip\fP, \fI-c\fP ] \fIpass-name\fP
+\fBshow\fP [ \fI--clip\fP, \fI-c\fP ] [ \fI--user\fP, \fI-u\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
.BR xclip (1)
and then restore the clipboard after 45 seconds.
+If \fI--user\fP or \fI-u\fP is specified then copy the user name from the password file to the
+clipboard.
.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
@@ -195,6 +197,18 @@ passworrrrrrrrd.
.br
^D
.TP
+Use multiline password file to store username
+.B zx2c4 at laptop ~ $ pass show Business/ice-cream-factory
+.br
+$ecretP4ssword
+.br
+User: Fred Flintstone
+.TP
+Copy username to clipboard
+.B zx2c4 at laptop ~ $ pass show Business/ice-cream-factory -c -u
+.br
+Copied username for Business/ice-cream-factory to clipboard. Will clear in 45 seconds.
+.TP
Generate new password
.B zx2c4 at laptop ~ $ pass generate Email/jasondonenfeld.com 15
.br
diff --git a/src/password-store.sh b/src/password-store.sh
index 55ed86e..653aa76 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -35,8 +35,10 @@ Usage:
Optionally reencrypt existing passwords using new gpg-id.
$program [ls] [subfolder]
List passwords.
- $program [show] [--clip,-c] pass-name
+ $program [show] [--clip,-c] [--user,-u] pass-name
Show existing password and optionally put it on the clipboard.
+ if the option user is applied then username is copied to clipboard
+ from password file.
If put on the clipboard, it will be cleared in 45 seconds.
$program insert [--echo,-e | --multiline,-m] [--force,-f] pass-name
Insert new password. Optionally, the console can be enabled echo
@@ -105,7 +107,9 @@ clip() {
echo "$before" | base64 -d | xclip -selection clipboard
) & disown
- echo "Copied $2 to clipboard. Will clear in 45 seconds."
+
+ echo "Copied $3 for $2 to clipboard. Will clear in 45 seconds."
+
}
tmpdir() {
if [[ -d /dev/shm && -w /dev/shm && -x /dev/shm ]]; then
@@ -192,17 +196,19 @@ fi
case "$command" in
show|ls|list)
clip=0
+ user=0
- opts="$($GETOPT -o c -l clip -n "$program" -- "$@")"
+ opts="$($GETOPT -o cu -l clip,user -n "$program" -- "$@")"
err=$?
eval set -- "$opts"
while true; do case $1 in
-c|--clip) clip=1; shift ;;
+ -u|--user) user=1; shift ;;
--) shift; break ;;
esac done
if [[ $err -ne 0 ]]; then
- echo "Usage: $program $command [--clip,-c] [pass-name]"
+ echo "Usage: $program $command [--clip,-c] [--user,-u] [pass-name]"
exit 1
fi
@@ -222,10 +228,15 @@ case "$command" in
fi
if [[ $clip -eq 0 ]]; then
exec gpg2 -d $GPG_OPTS "$passfile"
+
+ elif [[ $user -eq 1 ]]; then
+ username="$(gpg2 -d $GPG_OPTS "$passfile" | awk -F": " 'tolower($1) ~ /^user$/ {print $NF}')"
+ [[ -n $username ]] || exit 1
+ clip "$username" "$path" "username"
else
pass="$(gpg2 -d $GPG_OPTS "$passfile" | head -n 1)"
[[ -n $pass ]] || exit 1
- clip "$pass" "$path"
+ clip "$pass" "$path" "password"
fi
fi
;;
--
1.7.10.4
More information about the Password-Store
mailing list