pashage

Yet Another Opinionated Re-engineering of the Unix Password Store
git clone https://git.instinctive.eu/pashage.git
Log | Files | Refs | README | LICENSE

commit 5ee030b6c18f0ba02163c0b8c80cd06da3329a68
parent 61bde10c847f9b42789dd6d11b84612736a89de4
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Thu, 27 Nov 2025 21:57:46 +0000

Grep action is rewritten without subshell
Diffstat:
Mspec/action_spec.sh | 10++--------
Mspec/pashage_extra_spec.sh | 2+-
Mspec/usage_spec.sh | 2+-
Msrc/pashage.sh | 23++++++++++++++---------
4 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/spec/action_spec.sh b/spec/action_spec.sh @@ -1445,10 +1445,7 @@ Describe 'Action Functions' #|(B)subdir/(G)match(N): #|other } - start_do_grep(){ - ( cd "${PREFIX}" && do_grep '' "$@" ) - } - When call start_do_grep ot + When call do_grep "${PREFIX}" ot The status should be success The output should equal "$(result)" End @@ -1460,10 +1457,7 @@ Describe 'Action Functions' #|other #|suffix } - start_do_grep(){ - ( cd "${PREFIX}" && do_grep '' "$@" ) - } - When call start_do_grep -vea + When call do_grep "${PREFIX}" -vea The status should be success The output should equal "$(result)" End diff --git a/spec/pashage_extra_spec.sh b/spec/pashage_extra_spec.sh @@ -877,7 +877,7 @@ Describe 'Integrated Command Functions' When run cmd_grep foo The status should equal 1 The error should equal \ - "Fatal(1): false -d -i ${IDENTITIES_FILE} -- file.age" + "Fatal(1): false -d -i ${IDENTITIES_FILE} -- ${PREFIX}/extra/subdir/file.age" The output should be blank The result of function check_git_log should be successful End diff --git a/spec/usage_spec.sh b/spec/usage_spec.sh @@ -1197,7 +1197,7 @@ Describe 'Command-Line Parsing' When call cmd_grep -i pattern The status should be success The output should be blank - The error should equal '$ do_grep -i pattern' + The error should equal "$ do_grep ${PREFIX} -i pattern" End It 'reports a lack of argument' diff --git a/src/pashage.sh b/src/pashage.sh @@ -714,23 +714,28 @@ do_generate_show() { # $1: current subdirectory name # ... grep arguments do_grep() { - SUBDIR="$1" - shift - - glob_exists ./* + glob_exists "$1"/* [ "${ANSWER}" = y ] || return 0 unset ANSWER - for ARG in *; do + for ARG in "$1"/*; do if [ -d "${ARG}" ]; then - ( cd "${ARG}" && do_grep "${SUBDIR}${ARG}/" "$@" ) + shift + set -- "${ARG}" "$@" + do_grep "$@" elif [ "${ARG}" = "${ARG%.age}.age" ]; then - HEADER="${BLUE_TEXT}${SUBDIR}${BOLD_TEXT}" - HEADER="${HEADER}${ARG%.age}${NORMAL_TEXT}:" + HEADER="${ARG%/*}" + HEADER="${HEADER#"${PREFIX}"}" + HEADER="${HEADER#/}" + HEADER="${BLUE_TEXT}${HEADER}${HEADER:+/}" + HEADER="${HEADER}${BOLD_TEXT}${ARG##*/}" + HEADER="${HEADER%.age}${NORMAL_TEXT}:" SECRET="$(do_decrypt "${ARG}")" + shift do_grep_filter "$@" <<-EOF ${SECRET} EOF + set -- a "$@" fi done @@ -1448,7 +1453,7 @@ cmd_grep() { exit 1 fi - ( cd "${PREFIX}" && do_grep "" "$@" ) + do_grep "${PREFIX}" "$@" } cmd_gitconfig() {