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 a0dad36e686b3ff728af4e4347d9c4089aa847af
parent ec4d031b940089ad3caabc9056d1eb4ca063200d
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Thu, 30 Oct 2025 19:34:34 +0000

Raw list output is implemented
Diffstat:
Mspec/action_spec.sh | 53++++++++++++++++++++++++++++++++++++++++++++++++++---
Mspec/pashage_extra_spec.sh | 2--
Msrc/pashage.sh | 49++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 98 insertions(+), 6 deletions(-)

diff --git a/spec/action_spec.sh b/spec/action_spec.sh @@ -1775,11 +1775,58 @@ Describe 'Action Functions' End Describe 'do_list' - It 'is not implemented yet' + PREFIX="${SHELLSPEC_WORKDIR}/prefix" + + grep() { @grep "$@"; } + + setup() { + @mkdir -p "${PREFIX}/subdir/subsub" "${PREFIX}/empty" "${PREFIX}/other" + %putsn data >"${PREFIX}/root.age" + %putsn data >"${PREFIX}/subdir/hidden" + %putsn data >"${PREFIX}/subdir/subsub/old.gpg" + %putsn data >"${PREFIX}/other/lower.age" + } + + cleanup() { + @rm -rf "${PREFIX}" + } + + BeforeEach setup + AfterEach cleanup + + It 'displays everything without a pattern' + result() { + %text + #|Base/other/lower + #|Base/root + #|Base/subdir/subsub/old + } When call do_list "${PREFIX}" 'Base/' The status should be success - The output should be blank - The error should equal 'TODO: not implemented yet' + The output should equal "$(result)" + End + + It 'displays only matching files' + result() { + %text + #|Base/other/lower + #|Base/subdir/subsub/old + } + When call do_list "${PREFIX}" 'Base/' -i L + The status should be success + The output should equal "$(result)" + End + + It 'does not display matching directories' + When call do_list "${PREFIX}" 'Base/' t + The status should be success + The output should equal 'Base/root' + End + + It 'might not display anything' + When call do_list "${PREFIX}" 'Base/' z + The status should be success + The output should equal '' End End diff --git a/spec/pashage_extra_spec.sh b/spec/pashage_extra_spec.sh @@ -1238,7 +1238,6 @@ Describe 'Integrated Command Functions' Describe 'cmd_list_or_show' It 'displays the whole store as a raw list' - Pending 'not implemented yet' When call cmd_list_or_show --raw The status should be success The error should be blank @@ -1255,7 +1254,6 @@ Describe 'Integrated Command Functions' End It 'displays a subdirectory as a raw list' - Pending 'not implemented yet' When call cmd_list_or_show -r fluff The status should be success The error should be blank diff --git a/src/pashage.sh b/src/pashage.sh @@ -852,7 +852,54 @@ do_insert() { # $2: path prefix # ...: (optional) grep arguments to filter do_list() { - echo "TODO: not implemented yet" >&2 + ( cd "$1" && shift && do_list_cwd "$@" ) +} + +# Display an entry list +# $1: path prefix +# ...: (optional) grep arguments to filter +do_list_cwd() { + LIST_PREFIX="$1" + shift + + for ENTRY in *; do + [ -e "${ENTRY}" ] || continue + do_list_item "${ENTRY}" "${LIST_PREFIX}" "$@" + done + unset ENTRY + + unset LIST_PREFIX +} + +# Display an entry in a list +# $1: item name +# $2: full item path +# ...: (optional) grep arguments to filter +do_list_item() { + ITEM_NAME="$1" + ITEM_PATH="$2" + shift 2 + + if [ -d "${ITEM_NAME}" ]; then + do_list "${ITEM_NAME}" \ + "${ITEM_PATH}${ITEM_NAME}/" \ + "$@" + elif [ "${ITEM_NAME%.age}.age" = "${ITEM_NAME}" ]; then + if [ $# -eq 0 ] \ + || printf '%s\n' "${ITEM_NAME%.age}" | grep -q "$@" + then + printf '%s%s\n' "${ITEM_PATH}" "${ITEM_NAME%.age}" + fi + elif [ "${ITEM_NAME%.gpg}.gpg" = "${ITEM_NAME}" ]; then + if [ $# -eq 0 ] \ + || printf '%s\n' "${ITEM_NAME%.age}" | grep -q "$@" + then + printf '%s%s\n' "${ITEM_PATH}" "${ITEM_NAME%.gpg}" + fi + fi + + unset ITEM_NAME + unset ITEM_PATH } # Display a single directory or entry