[pass] [PATCH] Add find/search command

Bernardo da Costa bernardo.da-costa at polytechnique.org
Thu Apr 4 15:40:44 CEST 2013


On Thu, Apr 04, 2013 at 02:28:56PM +0200, Alexis wrote:

>  case "$command" in
> +	find|search)
> +		if [[ -z "$@" ]]; then
> +			echo "Usage: $program $command pass-names..."
> +			exit 1
> +		fi
> +		pattern="$(echo "$@" | sed -e 's/ /*|*/g')"
> +		tree -l --noreport --prune -P "*$pattern*" "$PREFIX/$path" | tail -n +2 | sed 's/\(.*\)\.gpg$/\1/'
> +		;;
I would use pattern="${@// /*|*}" to avoid having both external commands
and risk of quoting-mess. Unfortunately, this does not work (Bash will
do substitution first, then only after make a single variable out of
it.) So you could have

pattern="$@"
pattern="${pattern// /*|*}"

This is not a clear win for bash, but I still prefer avoiding echo as
much as I can. Of course, with echo you can do fancy things as replacing
\t and so on, but I see not a great deal of use in our case. I imagined
$* could work here in a single command, but have not succeeded, so I
leave as a research problem ;-)

Also, I'd write the final sed without replacement, just cutting:

sed 's/\.gpg$//'

Cheers,
-- 
Bernardo




More information about the Password-Store mailing list