From 295b968d5a3802bf3a16225ea2b216855f49630e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Fri, 8 Jan 2016 23:57:45 +0100 Subject: Allow passing '-u' to 'show' to print the 'User:' line --- src/password-store.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/password-store.sh b/src/password-store.sh index a0dcf2e..1da953c 100755 --- a/src/password-store.sh +++ b/src/password-store.sh @@ -19,6 +19,7 @@ CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}" GENERATED_LENGTH="${PASSWORD_STORE_GENERATED_LENGTH:-25}" CHARACTER_SET="${PASSWORD_STORE_CHARACTER_SET:-[:punct:][:alnum:]}" CHARACTER_SET_NO_SYMBOLS="${PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS:-[:alnum:]}" +USER_STRING="${PASSWORD_USER_STRING:-User: }" unset GIT_DIR GIT_WORK_TREE GIT_NAMESPACE GIT_INDEX_FILE GIT_INDEX_VERSION GIT_OBJECT_DIRECTORY GIT_COMMON_DIR export GIT_CEILING_DIRECTORIES="$PREFIX/.." @@ -267,6 +268,8 @@ cmd_version() { = Jason A. Donenfeld = = Jason@zx2c4.com = = = + = with Nec's modifications = + = = = http://www.passwordstore.org/ = ============================================ _EOF @@ -366,13 +369,14 @@ cmd_init() { } cmd_show() { - local opts selected_line clip=0 qrcode=0 - opts="$($GETOPT -o q::c:: -l qrcode::,clip:: -n "$PROGRAM" -- "$@")" + local opts selected_line clip=0 qrcode=0 user=0 + opts="$($GETOPT -o q::c::u -l qrcode::,clip::,user -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" while true; do case $1 in -q|--qrcode) qrcode=1; selected_line="${2:-1}"; shift 2 ;; -c|--clip) clip=1; selected_line="${2:-1}"; shift 2 ;; + -u|--user) user=1; shift 1;; --) shift; break ;; esac done @@ -386,6 +390,18 @@ cmd_show() { if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | $BASE64)" || exit $? echo "$pass" | $BASE64 -d + elif [[ $user -eq 1 ]]; then + local user="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep -m 1 "^${USER_STRING}" | sed -e "s/^${USER_STRING}"'\(.*\)/\1/')" + + [[ -n $user ]] || exit 1 + + if [[ $clip -eq 1 ]]; then + clip "$user" "$path" + elif [[ $qrcode -eq 1 ]]; then + qrcode "$pass" "$path" + else + echo "$user" + fi else [[ $selected_line =~ ^[0-9]+$ ]] || die "Clip location '$selected_line' is not a number." pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n +${selected_line} | head -n 1)" || exit $? -- cgit v1.2.3