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 6a286d4509cad4e0658b9e3a51c8ce2470faa777
parent 71724cda34eb835dfb79ff99ee9dde4cbe6b1084
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Sat, 16 Nov 2024 06:30:00 +0000

OVERWRITE instead of DECISION to communicate overwriting generation
Diffstat:
Mspec/action_spec.sh | 6+++---
Mspec/pashage_extra_spec.sh | 4++--
Mspec/usage_spec.sh | 34+++++++++++++++++-----------------
Msrc/pashage.sh | 19++++++++-----------
4 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/spec/action_spec.sh b/spec/action_spec.sh @@ -1131,7 +1131,7 @@ Describe 'Action Functions' It 'overwrites an existing file when forced' MULTILINE=no - DECISION=force + OVERWRITE=yes result(){ %text:expand #|$ scm_begin @@ -1151,7 +1151,7 @@ Describe 'Action Functions' It 'overwrites an existing file after confirmation' MULTILINE=no - DECISION=default + OVERWRITE=no yesno() { mocklog yesno "$@"; ANSWER=y @@ -1177,7 +1177,7 @@ Describe 'Action Functions' It 'does not overwrite an existing file without confirmation' MULTILINE=no - DECISION=default + OVERWRITE=no yesno() { mocklog yesno "$@"; ANSWER=n diff --git a/spec/pashage_extra_spec.sh b/spec/pashage_extra_spec.sh @@ -612,8 +612,8 @@ Describe 'Integrated Command Functions' End Describe 'cmd_generate' - DECISION=default MULTILINE=no + OVERWRITE=no SHOW=text It 'uses the character set given explicitly instead of environment' @@ -1509,8 +1509,8 @@ Describe 'Integrated Command Functions' # 'find' does not change the repository Example 'generate' - DECISION=default MULTILINE=no + OVERWRITE=no When run cmd_generate new-pass The status should equal 1 The error should equal 'There are already pending changes.' diff --git a/spec/usage_spec.sh b/spec/usage_spec.sh @@ -96,8 +96,8 @@ Describe 'Command-Line Parsing' do_generate() { mocklog do_generate "$@" %text:expand >&2 - #|DECISION=${DECISION} #|MULTILINE=${MULTILINE} + #|OVERWRITE=${OVERWRITE} #|SELECTED_LINE=${SELECTED_LINE} #|SHOW=${SHOW} } @@ -635,8 +635,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=text } @@ -651,8 +651,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 12 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=text } @@ -667,8 +667,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 12 [A-Z] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=text } @@ -683,8 +683,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path -f #|$ do_generate -f 25 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=text } @@ -699,8 +699,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=clip } @@ -715,8 +715,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=clip } @@ -731,8 +731,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=qrcode } @@ -747,8 +747,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=qrcode } @@ -763,8 +763,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=clip } @@ -779,8 +779,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=clip } @@ -795,8 +795,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=qrcode } @@ -811,8 +811,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:alnum:] - #|DECISION=default #|MULTILINE=no + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=qrcode } @@ -827,8 +827,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=yes + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=text } @@ -843,8 +843,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=default #|MULTILINE=yes + #|OVERWRITE=no #|SELECTED_LINE=1 #|SHOW=text } @@ -859,8 +859,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=force #|MULTILINE=no + #|OVERWRITE=yes #|SELECTED_LINE=1 #|SHOW=text } @@ -875,8 +875,8 @@ Describe 'Command-Line Parsing' %text #|$ check_sneaky_path secret #|$ do_generate secret 25 [:punct:][:alnum:] - #|DECISION=force #|MULTILINE=no + #|OVERWRITE=yes #|SELECTED_LINE=1 #|SHOW=text } diff --git a/src/pashage.sh b/src/pashage.sh @@ -610,8 +610,8 @@ do_encrypt() { # $1: secret name # $2: new password length # $3: new password charset -# DECISION: whether to ask before overwrite # MULTILINE: whether to re-use existing secret data +# OVERWRITE: whether to overwrite without confirmation do_generate() { NEW_PASS="$(random_chars "$2" "$3")" NEW_PASS_LEN="$(strlen "${NEW_PASS}")" @@ -652,13 +652,10 @@ do_generate() { unset WIP_FILE else - if [ -e "${PREFIX}/$1.age" ]; then - if ! [ "${DECISION}" = force ]; then - yesno "An entry already exists for $1. Overwrite it?" - [ "${ANSWER}" = y ] || return 0 - unset ANSWER - fi - + if [ -e "${PREFIX}/$1.age" ] && ! [ "${OVERWRITE}" = yes ]; then + yesno "An entry already exists for $1. Overwrite it?" + [ "${ANSWER}" = y ] || return 0 + unset ANSWER OVERWRITE=once fi @@ -1206,10 +1203,10 @@ cmd_generate() { PARSE_ERROR=yes break fi - DECISION=force + OVERWRITE=yes shift ;; -i|--in-place) - if [ "${DECISION}" = force ]; then + if [ "${OVERWRITE}" = yes ]; then PARSE_ERROR=yes break fi @@ -1245,7 +1242,7 @@ cmd_generate() { done if [ "${PARSE_ERROR}" = yes ] || [ $# -eq 0 ] || [ $# -gt 3 ] \ - || [ "${DECISION}-${MULTILINE}" = force-yes ] + || [ "${OVERWRITE}-${MULTILINE}" = yes-yes ] then cmd_usage 'Usage: ' generate >&2 exit 1