[pass] [PATCH] Add find/search command
Von Welch
von at vwelch.com
Sun Apr 6 00:30:20 CEST 2014
Here's my version of using 'find' that I've built up to include
directories, not hit on the .gpg extension and other gotchas.
Obviously it's intended for zsh with the argument quoting, but all the find
parts should be portable.
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
exit 1
fi
# Change dir to store so we can run 'find .' and not match
# on password store directory.
cd "${store}"
# All arguments escaped and joined into one string
search_string="${(j. .)${(q)@}}" ; shift
# Find first clause prunes .git/ directory
# Second clause matches entries with matching directory components
# Third clause matches any part of filename, ignoring .gpg suffic
# -iname and -ipath are case-insensitive
# sed command strips password store path prefix and .gpg suffix
find . -type d -name .git -prune \
-o -ipath "*/*${search_string}*/*" -print \
-o -iname "*${search_string}*.gpg" -type f -print \
| sed -e "s#${store}.##" -e 's#\.gpg$##' | sort
}
On Thu, Apr 4, 2013 at 9:53 AM, Jason A. Donenfeld <Jason at zx2c4.com> wrote:
> Hi Alexis,
>
> In the past I haven't been too keen on adding search functionality, as I
> think utilities like GNU Find are better suited, and since pass is just a
> standard directory tree...
>
> But lots of people want this feature, so it will land.
>
> That said, I want to figure out a way to also search directory names in
> addition to file names. This fits the most common organizational scheme for
> pass. Any suggestions on the best way to do this?
>
> I've rewritten your patch, and attached my current version here. Please
> base any improvements off of this one.
>
> Jason
>
> _______________________________________________
> Password-Store mailing list
> Password-Store at lists.zx2c4.com
> http://lists.zx2c4.com/listinfo.cgi/password-store-zx2c4.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20140405/0b3712d2/attachment.html>
More information about the Password-Store
mailing list