m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2014-04-15 18:09:22 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2014-04-15 18:09:22 +0200
commit73a20724e7f3eb412cff4d41cf98e6fca426274e (patch)
treed8924be815e5ba7ec726273a58946a75ef90038d /src
parent98a9867ff6e202b159861f2cd527395d7d5d6685 (diff)
grep: add new pass grep command
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/password-store.sh31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/password-store.sh b/src/password-store.sh
index ac3e20b..4266288 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -171,6 +171,8 @@ cmd_usage() {
$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.
+ $PROGRAM grep search-string
+ Search for password files containing search-string when decrypted.
$PROGRAM insert [--echo,-e | --multiline,-m] [--force,-f] pass-name
Insert new password. Optionally, echo the password back to the console
during entry. Or, optionally, the entry may be multiline. Prompt before
@@ -232,9 +234,9 @@ cmd_init() {
local passfile
find "$PREFIX/$id_path" -iname '*.gpg' | while read -r passfile; do
fake_uniqueness_safety="$RANDOM"
- passfile_dir=${passfile%/*}
- passfile_dir=${passfile_dir#$PREFIX}
- passfile_dir=${passfile_dir#/}
+ passfile_dir="${passfile%/*}"
+ passfile_dir="${passfile_dir#$PREFIX}"
+ passfile_dir="${passfile_dir#/}"
set_gpg_recipients "$passfile_dir"
$GPG -d $GPG_OPTS "$passfile" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile.new.$fake_uniqueness_safety" $GPG_OPTS &&
mv -v "$passfile.new.$fake_uniqueness_safety" "$passfile"
@@ -304,6 +306,28 @@ cmd_find() {
tree -l --noreport -P "*${terms// /*|*}*" --prune --matchdirs --caseinsensitive "$PREFIX" | tail -n +2 | sed 's/\.gpg$//'
}
+cmd_grep() {
+ if [[ $# -ne 1 ]]; then
+ echo "Usage: $PROGRAM $COMMAND search-string"
+ exit 1
+ fi
+ agent_check
+ local passfile
+ local passfile_dir
+ local grepresults
+ local search="$1"
+ find "$PREFIX" -iname '*.gpg' | while read -r passfile; do
+ grepresults="$($GPG -d $GPG_OPTS "$passfile" | grep --color=always "$search")"
+ [ $? -ne 0 ] && continue
+ passfile="${passfile%.gpg}"
+ passfile="${passfile#$PREFIX/}"
+ passfile_dir="${passfile%/*}"
+ passfile="${passfile##*/}"
+ printf "\e[94m$passfile_dir/\e[1m$passfile\e[0m:\n"
+ echo "$grepresults"
+ done
+}
+
cmd_insert() {
local multiline=0
local noecho=1
@@ -496,6 +520,7 @@ case "$1" in
version|--version) shift; cmd_version "$@"; ;;
show|ls|list) shift; cmd_show "$@"; ;;
find|search) shift; cmd_find "$@"; ;;
+ grep) shift; cmd_grep "$@"; ;;
insert) shift; cmd_insert "$@"; ;;
edit) shift; cmd_edit "$@"; ;;
generate) shift; cmd_generate "$@"; ;;