diff options
| author | Federico Angelilli <code@fedang.net> | 2023-12-22 16:35:13 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2023-12-22 16:35:13 +0100 |
| commit | fc3b8f0ebb1926636564b13b40b006ea5a70ce04 (patch) | |
| tree | 3a08df22e83921d80f5e4ba2530e5c3ba6d7d2f5 /crypt.sh | |
| parent | 227214b80f06a438710f2ce29efb3c9e0c24e410 (diff) | |
Add grep command
Diffstat (limited to 'crypt.sh')
| -rwxr-xr-x | crypt.sh | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -661,6 +661,19 @@ cmd_copy_move() { fi } +cmd_grep() { + [[ $# -lt 1 ]] && die "Usage: $PROGRAM $COMMAND [GREPOPTIONS] search-string" + local file results + while read -r -d "" file; do + results="$($GPG -d "${GPG_OPTS[@]}" "$file" | grep --color=always "$@")" + [[ $? -ne 0 ]] && continue + file="${file%.gpg}" + file="${file#$CRYPT_PATH/}" + echo "$(_color cyan,bold)$file$(_color reset):" + echo "$results" + done < <(find -L "$CRYPT_PATH" -path '*/.git' -prune -o -path '*/.extensions' -prune -o -iname '*.gpg' -print0) +} + cmd_help() { cat <<-EOF Usage: @@ -679,6 +692,9 @@ cmd_help() { $PROGRAM list [--plain] List the crypt structure, associating each file to its entry name + $PROGRAM grep [GREPOPTIONS] search-string + Run grep with GREPOPTIONS and search-string + $PROGRAM info List the crypt registered entries @@ -727,6 +743,7 @@ case "$COMMAND" in edit) shift; cmd_edit "$@" ;; insert) shift; cmd_insert "$@" ;; show) shift; cmd_show "$@" ;; + grep) shift; cmd_grep "$@" ;; list|ls) shift; cmd_list "$@" ;; move|mv) shift; cmd_copy_move "$@" ;; copy|cp) shift; cmd_copy_move "$@" ;; |
