m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-09-13 16:35:49 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2012-09-13 16:35:49 +0200
commitb718c8039e5a04f102c3d2bb9f920d1472c89da1 (patch)
tree918aeeb4822a951715b62b7267b0475ba9432360
parent709808d22cf09390b5404b7bfc42f3243d9577d4 (diff)
Allow avoiding the prompt for overwriting, with --force flag.
-rw-r--r--man/pass.15
-rwxr-xr-xsrc/password-store.sh13
2 files changed, 11 insertions, 7 deletions
diff --git a/man/pass.1 b/man/pass.1
index 0ef28c1..a124c32 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -71,12 +71,13 @@ clipboard using
.BR xclip (1)
and then restore the clipboard after 45 seconds.
.TP
-\fBinsert\fP [ \fI--no-echo\fP, \fI-n\fP | \fI--multiline\fP, \fI-m\fP ] \fIpass-name\fP
+\fBinsert\fP [ \fI--no-echo\fP, \fI-n\fP | \fI--multiline\fP, \fI-m\fP ] [ \fI--force\fP, \fI-f\fP ]\fIpass-name\fP
Insert a new password into the password store called \fIpass-name\fP. This will
read the new password from standard in. If \fI--no-echo\fP or \fI-n\fP is specified, do
disable keyboard echo when the password is entered and confirm the password by asking
for it twice. If \fI--multiline\fP or \fI-m\fP is specified, lines will be read until
-EOF or Ctrl+D is reached. Otherwise, only a single line from standard in is read.
+EOF or Ctrl+D is reached. Otherwise, only a single line from standard in is read. Prompt
+before overwriting an existing password, unless \fI--force\fP or \fI-f\fP is specified.
.TP
\fBedit\fP \fIpass-name\fP
Insert a new password or edit an existing password using the default text editor specified
diff --git a/src/password-store.sh b/src/password-store.sh
index 2488385..76c7385 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -37,9 +37,10 @@ Usage:
$program [show] [--clip,-c] pass-name
Show existing password and optionally put it on the clipboard.
If put on the clipboard, it will be cleared in 45 seconds.
- $program insert [--no-echo,-n | --multiline,-m] pass-name
+ $program insert [--no-echo,-n | --multiline,-m] [--force,-f] pass-name
Insert new password. Optionally, the console can be enabled to not
- echo the password back. Or, optionally, it may be multiline.
+ echo the password back. Or, optionally, it may be multiline. Prompt
+ before 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] pass-name pass-length
@@ -170,24 +171,26 @@ case "$command" in
insert)
ml=0
noecho=0
+ force=0
- opts="$(getopt -o mn -l multiline,no-echo -n $program -- "$@")"
+ opts="$(getopt -o mnf -l multiline,no-echo,force -n $program -- "$@")"
err=$?
eval set -- "$opts"
while true; do case $1 in
-m|--multiline) ml=1; shift ;;
-n|--no-echo) noecho=1; shift ;;
+ -f|--force) force=1; shift ;;
--) shift; break ;;
esac done
if [[ $err -ne 0 || ( $ml -eq 1 && $noecho -eq 1 ) || $# -ne 1 ]]; then
- echo "Usage: $program $command [--no-echo,-n | --multiline,-m] pass-name"
+ echo "Usage: $program $command [--no-echo,-n | --multiline,-m] [--force,-f] pass-name"
exit 1
fi
path="$1"
passfile="$PREFIX/$path.gpg"
- if [[ -e $passfile ]]; then
+ if [[ $force -eq 0 && -e $passfile ]]; then
prompt="An entry already exists for $path. Overwrite it [y/N]? "
read -p "$prompt" yesno
[[ $yesno == "y" || $yesno == "Y" ]] || exit 1