From 7ed0a70aa6d1fd502ff5443bced462d6dedd8511 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 14 Apr 2014 14:59:07 +0200 Subject: find: add find/search command This relies on a patched version of tree to work, unfortunately. Hopefully upstream will accept our patch. Signed-off-by: Jason A. Donenfeld --- src/password-store.sh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/password-store.sh') diff --git a/src/password-store.sh b/src/password-store.sh index a7a5604..706eada 100755 --- a/src/password-store.sh +++ b/src/password-store.sh @@ -43,6 +43,8 @@ usage() { Optionally reencrypt existing passwords using new gpg-id. $program [ls] [subfolder] List passwords. + $program find pass-names... + List passwords that match pass-names. $program [show] [--clip,-c] pass-name Show existing password and optionally put it on the clipboard. If put on the clipboard, it will be cleared in $CLIP_TIME seconds. @@ -71,7 +73,7 @@ usage() { } is_command() { case "$1" in - init|ls|list|show|insert|edit|generate|remove|rm|delete|git|help|--help|version|--version) return 0 ;; + init|ls|list|find|search|show|insert|edit|generate|remove|rm|delete|git|help|--help|version|--version) return 0 ;; *) return 1 ;; esac } @@ -268,6 +270,25 @@ case "$command" in exit 1 fi ;; + find|search) + if [[ -z "$@" ]]; then + echo "Usage: $program $command pass-names..." + exit 1 + fi + if ! tree --help |& grep -q "^ --matchdirs"; then + echo "ERROR: $program: incompatible tree command" + echo + echo "Your version of the tree command is missing the relevent patch to add the" + echo "--matchdirs switch. Please ask your distribution to patch your version of" + echo "tree with:" + echo " http://git.zx2c4.com/password-store/plain/contrib/tree-1.6.0-matchdirs.patch" + echo "Sorry for the inconvenience." + exit 1 + fi + terms="$@" + echo "Search Terms: $terms" + tree -l --noreport -P "*${terms// /*|*}*" --prune --matchdirs "$PREFIX" | tail -n +2 | sed 's/\.gpg$//' + ;; insert) multiline=0 noecho=1 -- cgit v1.2.3-54-g00ecf