#!/bin/sh

# reliable password fuzzy searcher

: ${PASSWORD_STORE_DIR?"Error var not set"}
cd "${PASSWORD_STORE_DIR}" || exit 1

PASSTOOL=spm
type ${PASSTOOL} 2>/dev/null || PASSTOOL=pass

selection="$(find -L . -name '*.gpg' | sed 's/.gpg$//g' | ${FUZZER})"

test -z "${selection}" || {
	case ${selection} in
        *totp/*) pass ${1:-"otp"} "${selection}" ;;
        ?*)pass ${1:-"show"} "${selection}" ;;
	esac
}
