commit 4bb977a73730be53dacbce4109211bff5776a2a5
parent bee5dc2136b7ffc1e4d2ac33a567d49fa60f91d3
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Tue, 28 Oct 2025 20:57:13 +0000
List command has a flag to output a raw list of entries
Diffstat:
3 files changed, 104 insertions(+), 11 deletions(-)
diff --git a/spec/pashage_extra_spec.sh b/spec/pashage_extra_spec.sh
@@ -1,5 +1,5 @@
# pashage - age-backed POSIX password manager
-# Copyright (C) 2024 Natasha Kerensikova
+# Copyright (C) 2024-2025 Natasha Kerensikova
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -1237,6 +1237,36 @@ Describe 'Integrated Command Functions'
End
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
+ expected_out() { %text
+ #|extra/subdir/file
+ #|fluff/one
+ #|fluff/three
+ #|fluff/two
+ #|old
+ #|stale
+ #|subdir/file
+ }
+ The output should equal "$(expected_out)"
+ 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
+ expected_out() { %text
+ #|fluff/one
+ #|fluff/three
+ #|fluff/two
+ }
+ The output should equal "$(expected_out)"
+ End
+
It 'decrypts a GPG secret in the store using GPG'
GPG=mock-gpg
gpg() { false; }
@@ -1296,7 +1326,7 @@ Describe 'Integrated Command Functions'
The status should equal 1
The output should be blank
expected_err() { %text
- #|Usage: prg [list] [subfolder]
+ #|Usage: prg [list] [--raw,-r] [subfolder]
#| prg [show] [--clip[=line-number],-c[line-number] |
#| --qrcode[=line-number],-q[line-number]] pass-name
}
@@ -1310,7 +1340,7 @@ Describe 'Integrated Command Functions'
The status should equal 1
The output should be blank
expected_err() { %text
- #|Usage: prg [list] [subfolder]
+ #|Usage: prg [list] [--raw,-r] [subfolder]
}
The error should equal "$(expected_err)"
End
diff --git a/spec/usage_spec.sh b/spec/usage_spec.sh
@@ -1,5 +1,5 @@
# pashage - age-backed POSIX password manager
-# Copyright (C) 2024 Natasha Kerensikova
+# Copyright (C) 2024-2025 Natasha Kerensikova
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -115,6 +115,7 @@ Describe 'Command-Line Parsing'
do_list_or_show() {
mocklog do_list_or_show "$@"
%text:expand >&2
+ #|LIST_VIEW=${LIST_VIEW}
#|SELECTED_LINE=${SELECTED_LINE}
#|SHOW=${SHOW}
}
@@ -1673,10 +1674,25 @@ Describe 'Command-Line Parsing'
Describe 'cmd_list_or_show'
COMMAND=
- It 'lists the whole store'
+ It 'lists the whole store as a list'
result() {
%text | @sed 's/\$$//'
#|$ do_list_or_show $
+ #|LIST_VIEW=yes
+ #|SELECTED_LINE=1
+ #|SHOW=text
+ }
+ When call cmd_list_or_show -r
+ The status should be success
+ The output should be blank
+ The error should equal "$(result)"
+ End
+
+ It 'lists the whole store as a tree'
+ result() {
+ %text | @sed 's/\$$//'
+ #|$ do_list_or_show $
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -1693,12 +1709,15 @@ Describe 'Command-Line Parsing'
#|$ check_sneaky_path arg2
#|$ check_sneaky_path arg3
#|$ do_list_or_show arg1
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=text
#|$ do_list_or_show arg2
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=text
#|$ do_list_or_show arg3
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -1713,6 +1732,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path -c
#|$ do_list_or_show -c
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=text
}
@@ -1727,6 +1747,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path arg
#|$ do_list_or_show arg
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=clip
}
@@ -1741,6 +1762,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path arg
#|$ do_list_or_show arg
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=clip
}
@@ -1755,6 +1777,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path arg
#|$ do_list_or_show arg
+ #|LIST_VIEW=no
#|SELECTED_LINE=2
#|SHOW=clip
}
@@ -1769,6 +1792,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path arg
#|$ do_list_or_show arg
+ #|LIST_VIEW=no
#|SELECTED_LINE=2
#|SHOW=clip
}
@@ -1783,6 +1807,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path arg
#|$ do_list_or_show arg
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=qrcode
}
@@ -1797,6 +1822,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path arg
#|$ do_list_or_show arg
+ #|LIST_VIEW=no
#|SELECTED_LINE=1
#|SHOW=qrcode
}
@@ -1811,6 +1837,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path arg
#|$ do_list_or_show arg
+ #|LIST_VIEW=no
#|SELECTED_LINE=3
#|SHOW=qrcode
}
@@ -1825,6 +1852,7 @@ Describe 'Command-Line Parsing'
%text
#|$ check_sneaky_path arg
#|$ do_list_or_show arg
+ #|LIST_VIEW=no
#|SELECTED_LINE=3
#|SHOW=qrcode
}
@@ -1834,10 +1862,40 @@ Describe 'Command-Line Parsing'
The error should equal "$(result)"
End
+ It 'shows an entry as a raw list (shot option)'
+ result() {
+ %text
+ #|$ check_sneaky_path arg
+ #|$ do_list_or_show arg
+ #|LIST_VIEW=yes
+ #|SELECTED_LINE=1
+ #|SHOW=text
+ }
+ When call cmd_list_or_show -r arg
+ The status should be success
+ The output should be blank
+ The error should equal "$(result)"
+ End
+
+ It 'shows an entry as a raw list (long option)'
+ result() {
+ %text
+ #|$ check_sneaky_path arg
+ #|$ do_list_or_show arg
+ #|LIST_VIEW=yes
+ #|SELECTED_LINE=1
+ #|SHOW=text
+ }
+ When call cmd_list_or_show --raw arg
+ The status should be success
+ The output should be blank
+ The error should equal "$(result)"
+ End
+
It 'reports incompatible show options'
cat() { @cat; }
result() { %text
- #|Usage: prg [list] [subfolder]
+ #|Usage: prg [list] [--raw,-r] [subfolder]
#| prg [show] [--clip[=line-number],-c[line-number] |
#| --qrcode[=line-number],-q[line-number]] pass-name
}
@@ -1850,7 +1908,7 @@ Describe 'Command-Line Parsing'
It 'reports a bad option for both commands'
cat() { @cat; }
result() { %text
- #|Usage: prg [list] [subfolder]
+ #|Usage: prg [list] [--raw,-r] [subfolder]
#| prg [show] [--clip[=line-number],-c[line-number] |
#| --qrcode[=line-number],-q[line-number]] pass-name
}
@@ -1864,7 +1922,7 @@ Describe 'Command-Line Parsing'
COMMAND=list
cat() { @cat; }
result() { %text
- #|Usage: prg [list] [subfolder]
+ #|Usage: prg [list] [--raw,-r] [subfolder]
}
When run cmd_list_or_show -f arg
The output should be blank
diff --git a/src/pashage.sh b/src/pashage.sh
@@ -1,6 +1,6 @@
#!/bin/sh
# pashage - age-backed POSIX password manager
-# Copyright (C) 2024 Natasha Kerensikova
+# Copyright (C) 2024-2025 Natasha Kerensikova
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -850,6 +850,7 @@ do_insert() {
# Display a single directory or entry
# $1: entry name
do_list_or_show() {
+ : TODO use "${LIST_VIEW-}"
if [ -z "$1" ]; then
do_tree "${PREFIX}" "Password Store"
elif [ -f "${PREFIX}/$1.age" ]; then
@@ -1476,6 +1477,7 @@ cmd_insert() {
}
cmd_list_or_show() {
+ LIST_VIEW=no
PARSE_ERROR=no
SELECTED_LINE=1
USE_CLIP=no
@@ -1505,6 +1507,9 @@ cmd_list_or_show() {
SELECTED_LINE="${1#--qrcode=}"
USE_QRCODE=yes
shift ;;
+ -r|--raw)
+ LIST_VIEW=yes
+ shift ;;
--)
shift
break ;;
@@ -1649,10 +1654,10 @@ cmd_usage(){
case "${ARG}" in
list)
cat <<EOF
-${F}${PROGRAM} [list] [subfolder]
+${F}${PROGRAM} [list] [--raw,-r] [subfolder]
EOF
[ "${VERBOSE}" = yes ] && cat <<EOF
-${I} List passwords.
+${I} List passwords as a tree or as a raw list.
EOF
;;
show)