commit 61e55fd661d880d94884704a97c53dd54480bee2
parent 5059619f5482624fb6bc553161ad5791631b7e40
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date: Sat, 21 Sep 2024 12:16:44 +0000
Generate command is aligned with pass behavior
Diffstat:
3 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/spec/action_spec.sh b/spec/action_spec.sh
@@ -889,6 +889,7 @@ Describe 'Action Functions'
Describe 'do_generate'
PREFIX="${SHELLSPEC_WORKDIR}/prefix"
+ SHOW=none
dd() { %- 0123456789 ; }
dirname() { @dirname "$@"; }
@@ -950,7 +951,7 @@ Describe 'Action Functions'
#|$ do_encrypt sub/new.age
#|> 0123456789
#|$ scm_add ${PREFIX}/sub/new.age
- #|$ scm_commit Add generated password for sub/new
+ #|$ scm_commit Add generated password for sub/new.
#|$ do_show sub/new
#|> 0123456789
}
@@ -959,6 +960,29 @@ Describe 'Action Functions'
The error should equal "$(result)"
End
+ It 'displays a title before text output'
+ SHOW=text
+ BOLD_TEXT='(B)'
+ NORMAL_TEXT='(N)'
+ UNDERLINE_TEXT='(U)'
+ NO_UNDERLINE_TEXT='(!U)'
+ result(){
+ %text:expand
+ #|$ scm_begin
+ #|$ mkdir -p -- ${PREFIX}/sub
+ #|$ do_encrypt sub/new.age
+ #|> 0123456789
+ #|$ scm_add ${PREFIX}/sub/new.age
+ #|$ scm_commit Add generated password for sub/new.
+ #|$ do_show sub/new
+ #|> 0123456789
+ }
+ When call do_generate sub/new 10 '[alnum:]'
+ The output should equal \
+ '(B)The generated password for (U)sub/new(!U) is:(N)'
+ The error should equal "$(result)"
+ End
+
It 'overwrites an existing file when forced'
OVERWRITE=no
DECISION=force
@@ -969,7 +993,7 @@ Describe 'Action Functions'
#|$ do_encrypt existing.age
#|> 0123456789
#|$ scm_add ${PREFIX}/existing.age
- #|$ scm_commit Add generated password for existing
+ #|$ scm_commit Add generated password for existing.
#|$ do_show existing
#|> 0123456789
}
@@ -993,7 +1017,7 @@ Describe 'Action Functions'
#|$ do_encrypt existing.age
#|> 0123456789
#|$ scm_add ${PREFIX}/existing.age
- #|$ scm_commit Add generated password for existing
+ #|$ scm_commit Add generated password for existing.
#|$ do_show existing
#|> 0123456789
}
@@ -1044,7 +1068,7 @@ Describe 'Action Functions'
#|> line 3
#|$ mv ${PREFIX}/existing-XXXXXXXXX.age ${PREFIX}/existing.age
#|$ scm_add ${PREFIX}/existing.age
- #|$ scm_commit Replace generated password for existing
+ #|$ scm_commit Replace generated password for existing.
#|$ do_show existing
#|> 0123456789
}
diff --git a/src/pashage.sh b/src/pashage.sh
@@ -687,10 +687,19 @@ do_generate() {
fi
scm_add "${PREFIX}/$1.age"
- scm_commit "${VERB} generated password for $1"
+ scm_commit "${VERB} generated password for $1."
unset VERB
+ if [ "${SHOW}" = text ]; then
+ printf '%sThe generated password for %s%s%s is:%s\n' \
+ "${BOLD_TEXT}" \
+ "${UNDERLINE_TEXT}" \
+ "$1" \
+ "${NO_UNDERLINE_TEXT}" \
+ "${NORMAL_TEXT}"
+ fi
+
do_show "$1" <<-EOF
${NEW_PASS}
EOF
diff --git a/src/run.sh b/src/run.sh
@@ -54,11 +54,15 @@ BOLD_TEXT=""
NORMAL_TEXT=""
RED_TEXT=""
BLUE_TEXT=""
+UNDERLINE_TEXT=""
+NO_UNDERLINE_TEXT=""
if [ -n "${CLICOLOR-}" ]; then
BOLD_TEXT="$(printf '\033[1m')"
NORMAL_TEXT="$(printf '\033[0m')"
RED_TEXT="$(printf '\033[31m')"
BLUE_TEXT="$(printf '\033[34m')"
+ UNDERLINE_TEXT="$(printf '\033[4m')"
+ NO_UNDERLINE_TEXT="$(printf '\033[24m')"
fi
### Git environment clean-up