[pass] 'pass find gpg' returns everything

Von Welch von at vwelch.com
Thu Jul 30 20:47:30 CEST 2015


FYI, What follows is the zsh function I use to search my password store
based on 'find.' I've tuned it to match any part of directories and stores
(case insensitively), but not the gpg extension or the password store path
or git directory. sed is used to prune the .gpg extension from store files.

Von


# Search passwords for string and return matches, one per line
search_pass() {
    local store="${PASSWORD_STORE_DIR:-$HOME/.password-store}"

    if test $# -ne 1 ; then
      echo "Usage: $0 <search_string>" 1>&2
      return 1
    fi

    # Change dir to store so we can run 'find .' and not match
    # on password store directory.
    pushd -q "${store}"

    # All arguments escaped and joined into one string
    search_string="${(j. .)${(q)@}}" ; shift

    # Find first clause prunes .git/ directory
    # Second clause matches full paths with matching directory components
    # Third clause matches any part of filename, ignoring .gpg suffix
    # -iname and -ipath are case-insensitive
    # sed command strips path prefix and .gpg suffix
    find . -type d -name .git -prune \
      -o -ipath "*/*${search_string}*/*" -type f -print \
      -o -iname "*${search_string}*.gpg" -type f -print \
      | sed -e "s#./##" -e 's#\.gpg$##' | sort
    popd -q
}



On Thu, Jul 30, 2015 at 6:27 AM Lenz Weber <mail at lenzw.de> wrote:

> Am 29.07.2015 um 12:57 schrieb nfb:
> > But...
> >
> >
> > » tree -C -l --noreport -P 'gpg*' --prune --matchdirs --ignore-case
> > PASSDIR/
> > PASSDIR/
> > ├── GPG
> > │   ├── firstkey.gpg
> > │   └── secondkey.gpg
> > └── homeserver
> >     └── gpgkey.gpg
> >
> >
> > which is good...
> >
> > Now this seems to be like this because in the pass script, the line
> > preceding the tree command defines the 'terms' variable, which adds
> > an asterisk in front of the parameters:
> >
> > local terms="*$(printf '%s*|*' "$@")"
> >
> > Maybe the culprit is here, but i can't figure out how to test it right
> > now...
> >
>
> Such a solution would only search at the beginning of a word - I doubt
> thats what is intended by the search command.
>
> >> So to fix this without meddling with tree, we would need some awk
> >> magic, and that could get a bit ugly.
> >> Anyone got a better solution?
> > What about not using .gpg extension at all within the password-store?
> >
> I doubt that change would be accepted - not only would it change a
> paradigma of pass, it would also be incompatible to all existing
> isntallations.
> _______________________________________________
> Password-Store mailing list
> Password-Store at lists.zx2c4.com
> http://lists.zx2c4.com/mailman/listinfo/password-store
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20150730/47d28571/attachment-0001.html>


More information about the Password-Store mailing list