aboutsummaryrefslogtreecommitdiff
path: root/otp.bash
diff options
context:
space:
mode:
Diffstat (limited to 'otp.bash')
-rwxr-xr-xotp.bash45
1 files changed, 26 insertions, 19 deletions
diff --git a/otp.bash b/otp.bash
index df04d4f..f2a90e2 100755
--- a/otp.bash
+++ b/otp.bash
@@ -90,10 +90,10 @@ Usage:
Generate an OTP code and optionally put it on the clipboard.
If put on the clipboard, it will be cleared in $CLIP_TIME seconds.
- $PROGRAM otp insert [--force,-f] [--echo,-e] [uri] pass-name
- Insert a new OTP key URI. If one is not supplied, it will be read from
- stdin. Optionally, echo the input. Prompt before overwriting existing
- password unless forced.
+ $PROGRAM otp insert [--force,-f] [--echo,-e] [pass-name]
+ Prompt for and insert a new OTP key URI. If pass-name is not supplied,
+ use the URI label. Optionally, echo the input. Prompt before overwriting
+ existing password unless forced. This command accepts input from stdin.
$PROGRAM otp uri [--clip,-c] [--qrcode,-q] pass-name
Display the key URI stored in pass-name. Optionally, put it on the
@@ -118,31 +118,38 @@ cmd_otp_insert() {
--) shift; break ;;
esac done
- [[ $err -ne 0 || ($# -ne 1 && $# -ne 2) ]] && die "Usage: $PROGRAM $COMMAND insert [--force,-f] [uri] pass-name"
+ [[ $err -ne 0 ]] && die "Usage: $PROGRAM $COMMAND insert [--force,-f] [pass-name]"
- local path uri
+ local prompt path uri
if [[ $# -eq 1 ]]; then
path="$1"
- if [[ -t 0 ]]; then
- if [[ $echo -eq 0 ]]; then
- read -r -p "Enter otpauth:// URI for $path: " -s uri || exit 1
- echo
- read -r -p "Retype otpauth:// URI for $path: " -s uri_again || exit 1
- echo
- [[ "$uri" == "$uri_again" ]] || die "Error: the entered URIs do not match."
- else
- read -r -p "Enter otpauth:// URI for $path: " -e uri
- fi
+ prompt="$path"
+ else
+ prompt="this token"
+ fi
+
+ if [[ -t 0 ]]; then
+ if [[ $echo -eq 0 ]]; then
+ read -r -p "Enter otpauth:// URI for $prompt: " -s uri || exit 1
+ echo
+ read -r -p "Retype otpauth:// URI for $prompt: " -s uri_again || exit 1
+ echo
+ [[ "$uri" == "$uri_again" ]] || die "Error: the entered URIs do not match."
else
- read -r uri
+ read -r -p "Enter otpauth:// URI for $prompt: " -e uri
fi
else
- uri="$1"
- path="$2"
+ read -r uri
fi
otp_parse_uri "$uri"
+ if [[ -z "$path" ]]; then
+ [[ -n "$otp_issuer" ]] && path+="$otp_issuer/"
+ path+="$otp_accountname"
+ yesno "Insert into $path?"
+ fi
+
otp_insert "$path" $force "$otp_uri" "Add OTP secret for $path to store."
}