<div dir="ltr"><div><div><div><div>Hello everyone,<br></div>Up for discussion, it would be useful to allow extraction from pass a selection of character indexes.<br></div>My use case is where some providers (i.e banks) want character 0, 3, 5 from a password. I modify the show command to accept --index(-i)<br></div>  i.e show -i0,3,5 for the password p@ssword would output 'p s o'<br><br></div><div>Attached is an initial patch, all feedback welcome :)<br></div><div><div><div><div><div><div><div><div><br><br>diff --git a/src/password-store.sh b/src/password-store.sh<br>index d77ff12..bcc8d62 100755<br>--- a/src/password-store.sh<br>+++ b/src/password-store.sh<br>@@ -263,8 +263,8 @@ cmd_usage() {<br>             List passwords.<br>         $PROGRAM find pass-names...<br>             List passwords that match pass-names.<br>-        $PROGRAM [show] [--clip[=line-number],-c[line-number]] pass-name<br>-            Show existing password and optionally put it on the clipboard.<br>+        $PROGRAM [show] [--clip[=line-number],-c[line-number]],[--index[=indexes],-i[=indexes] pass-name<br>+            Show existing password, optionally put it on the clipboard, optionally extract out character indexes (i.e -i0,3,5).<br>             If put on the clipboard, it will be cleared in $CLIP_TIME seconds.<br>         $PROGRAM grep search-string<br>             Search for password files containing search-string when decrypted.<br>@@ -346,26 +346,33 @@ cmd_init() {<br><br> cmd_show() {<br>     local opts selected_line clip=0 qrcode=0<br>-    opts="$($GETOPT -o q::c:: -l qrcode::,clip:: -n "$PROGRAM" -- "$@")"<br>+    opts="$($GETOPT -o q::c::i:: -l qrcode::,clip::,index:: -n "$PROGRAM" -- "$@")"<br>     local err=$?<br>     eval set -- "$opts"<br>     while true; do case $1 in<br>         -q|--qrcode) qrcode=1; selected_line="${2:-1}"; shift 2 ;;<br>         -c|--clip) clip=1; selected_line="${2:-1}"; shift 2 ;;<br>+        -i|--index) index=1; _=$IFS IFS="," indexes=(${2:-1}) IFS=$_; shift 2 ;;<br>         --) shift; break ;;<br>     esac done<br><br>-    [[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]] [--qrcode[=line-number],-q[line-number]] [pass-name]"<br>+    [[ $err -ne 0 || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--clip[=line-number],-c[line-number]],[--index=[character-indexes],-i[character-indexes] [--qrcode[=line-number],-q[line-number]] [pass-name]"<br><br>     local path="$1"<br>     local passfile="$PREFIX/$path.gpg"<br>     check_sneaky_paths "$path"<br>     if [[ -f $passfile ]]; then<br>+        local pass=`$GPG -d "${GPG_OPTS[@]}" "$passfile"`<br>+<br>+        if [[ $index -eq 1 ]]; then<br>+            pass=$(for i in ${indexes[*]}; do echo ${pass:i:1}; done) || exit $?<br>+        fi<br>         if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then<br>-            $GPG -d "${GPG_OPTS[@]}" "$passfile" || exit $?<br>+            [[ -n $pass ]] || exit $?<br>+            echo $pass<br>         else<br>             [[ $selected_line =~ ^[0-9]+$ ]] || die "Clip location '$selected_line' is not a number."<br>-            local pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | tail -n +${selected_line} | head -n 1)"<br>+            pass="$(echo $pass | tail -n +${selected_line} | head -n 1)"<br>             [[ -n $pass ]] || die "There is no password to put on the clipboard at line ${selected_line}."<br>             if [[ $clip -eq 1 ]]; then<br>                 clip "$pass" "$path"<br>diff --git a/tests/t0020-show-tests.sh b/tests/t0020-show-tests.sh<br>index a4b782f..c005c7d 100755<br>--- a/tests/t0020-show-tests.sh<br>+++ b/tests/t0020-show-tests.sh<br>@@ -19,4 +19,24 @@ test_expect_success 'Test "show" of nonexistant password' '<br>     test_must_fail "$PASS" show cred2<br> '<br><br>+test_expect_success 'Test "show" of single character' '<br>+    "$PASS" insert -e "cred3"<<<"p@ssword!" &&<br>+    [[ $("$PASS" show -i1 cred3) == "@" ]]<br>+'<br>+<br>+test_expect_success 'Test "show" of first character' '<br>+    "$PASS" insert -e "cred3"<<<"p@ssword!" &&<br>+    [[ $("$PASS" show -i0 cred3) == "p" ]]<br>+'<br>+<br>+test_expect_success 'Test "show" of last character' '<br>+    "$PASS" insert -e "cred3"<<<"p@ssword!" &&<br>+    [[ $("$PASS" show -i8 cred3) == "!" ]]<br>+'<br>+<br>+test_expect_success 'Test "show" of multiple characters' '<br>+    "$PASS" insert -e "cred3"<<<"p@ssword!" &&<br>+    [[ $("$PASS" show -i1,5 cred3) == "@ o" ]]<br>+'<br>+<br> test_done<br clear="all"><br>-- <br><div class="gmail_signature">Peter Brooks<br></div>
</div></div></div></div></div></div></div></div></div>