From e6502b345b788fb6367fce91b2cb0b85d1385d46 Mon Sep 17 00:00:00 2001
From: Allan Odgaard <git@abetarda.com>
Date: Thu, 15 Jan 2015 11:21:11 +0700
Subject: [PATCH] grep: Fix path for items in the root of the password store

Previously using grep would show `$PREFIX/foo.gpg` as `foo/foo`.
---
 src/password-store.sh | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git src/password-store.sh src/password-store.sh
index d4e9515..a491ba4 100755
--- src/password-store.sh
+++ src/password-store.sh
@@ -344,11 +344,10 @@ cmd_grep() {
 	while read -r -d "" passfile; do
 		grepresults="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | grep --color=always "$search")"
 		[ $? -ne 0 ] && continue
-		passfile="${passfile%.gpg}"
-		passfile="${passfile#$PREFIX/}"
-		local passfile_dir="${passfile%/*}"
-		passfile="${passfile##*/}"
-		printf "\e[94m%s/\e[1m%s\e[0m:\n" "$passfile_dir" "$passfile"
+		local passfile_dir="$(dirname "$passfile")/"
+		passfile_dir="${passfile_dir#$PREFIX/}"
+		passfile="$(basename "$passfile" .gpg)"
+		printf "\e[94m%s\e[1m%s\e[0m:\n" "$passfile_dir" "$passfile"
 		echo "$grepresults"
 	done < <(find -L "$PREFIX" -iname '*.gpg' -print0)
 }
-- 
2.2.2

