aboutsummaryrefslogtreecommitdiffstatshomepage
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
parentCheck for agent before batch processes (diff)
downloadpassword-store-73a20724e7f3eb412cff4d41cf98e6fca426274e.tar.xz
password-store-73a20724e7f3eb412cff4d41cf98e6fca426274e.zip
grep: add new pass grep command
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--man/pass.16
-rwxr-xr-xsrc/password-store.sh31
2 files changed, 34 insertions, 3 deletions
diff --git a/man/pass.1 b/man/pass.1
index 0035cdb..434c492 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -72,6 +72,12 @@ by using the
.BR tree (1)
program. This command is alternatively named \fBlist\fP.
.TP
+\fBgrep\fP \fIsearch-string\fP
+Searches inside each decrypted password file for \fIsearch-string\fP, and displays line
+containing matched string along with filename. Uses
+.BR grep (1)
+for matching.
+.TP
\fBfind\fP \fIpass-names\fP...
List names of passwords inside the tree that match \fIpass-names\fP by using the
.BR tree (1)
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 "$@"; ;;