[PATCH 2/2] generate: add -e, --edit for adding more metadata
Arsen Arsenović
arsen at aarsen.me
Sun Jun 27 20:23:59 UTC 2021
This allows users to, in one command, generate a password and fill out
the rest of the data they want to have in a given password file,
allowing them to reduce the amount of git operations done on the
password file and save some time.
---
src/password-store.sh | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/password-store.sh b/src/password-store.sh
index d1d8aa6..ab66168 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -295,7 +295,7 @@ cmd_usage() {
overwriting existing password unless forced.
$PROGRAM edit pass-name
Insert a new password or edit an existing password using ${EDITOR:-vi}.
- $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] pass-name [pass-length]
+ $PROGRAM generate [--no-symbols,-n] [--clip,-c] [--in-place,-i | --force,-f] [--edit,-e] pass-name [pass-length]
Generate a new password of pass-length (or $GENERATED_LENGTH if unspecified) with optionally no symbols.
Optionally put it on the clipboard and clear board after $CLIP_TIME seconds.
Prompt before overwriting existing password unless forced.
@@ -510,8 +510,8 @@ cmd_edit() {
}
cmd_generate() {
- local opts qrcode=0 clip=0 force=0 characters="$CHARACTER_SET" inplace=0 pass
- opts="$($GETOPT -o nqcif -l no-symbols,qrcode,clip,in-place,force -n "$PROGRAM" -- "$@")"
+ local opts qrcode=0 clip=0 force=0 characters="$CHARACTER_SET" inplace=0 pass edit=0
+ opts="$($GETOPT -o nqcife -l no-symbols,qrcode,clip,in-place,force,edit -n "$PROGRAM" -- "$@")"
local err=$?
eval set -- "$opts"
while true; do case $1 in
@@ -520,10 +520,11 @@ cmd_generate() {
-c|--clip) clip=1; shift ;;
-f|--force) force=1; shift ;;
-i|--in-place) inplace=1; shift ;;
+ -e|--edit) edit=1; shift ;;
--) shift; break ;;
esac done
- [[ $err -ne 0 || ( $# -ne 2 && $# -ne 1 ) || ( $force -eq 1 && $inplace -eq 1 ) || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--no-symbols,-n] [--clip,-c] [--qrcode,-q] [--in-place,-i | --force,-f] pass-name [pass-length]"
+ [[ $err -ne 0 || ( $# -ne 2 && $# -ne 1 ) || ( $force -eq 1 && $inplace -eq 1 ) || ( $qrcode -eq 1 && $clip -eq 1 ) ]] && die "Usage: $PROGRAM $COMMAND [--no-symbols,-n] [--clip,-c] [--qrcode,-q] [--in-place,-i | --force,-f] [--edit,-e] pass-name [pass-length]"
local path="$1"
local length="${2:-$GENERATED_LENGTH}"
check_sneaky_paths "$path"
@@ -547,6 +548,10 @@ cmd_generate() {
$GPG -d "${GPG_OPTS[@]}" "$passfile" | sed 1d >> "$tmp_file"
fi
+ if [[ $edit -eq 1 ]]; then
+ ${EDITOR:-vi} "$tmp_file"
+ fi
+
while ! $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" "$tmp_file"; do
yesno "GPG encryption failed. Would you like to try again?"
done
--
2.31.1
More information about the Password-Store
mailing list