aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2020-07-06 01:27:56 +0530
committerAkshay Nair <phenax5@gmail.com>2020-07-06 01:27:56 +0530
commit43ae89ea3a3ca139378cb7b6d4580248a44358b6 (patch)
treed8bf4f60836955a48eb20105ee2df189cf46dd80
parent5eabdaaf224750b60a838e0b7ce6ef0e092b3ea3 (diff)
downloadanypinentry-43ae89ea3a3ca139378cb7b6d4580248a44358b6.tar.gz
anypinentry-43ae89ea3a3ca139378cb7b6d4580248a44358b6.zip
Implements error notification and repeat error text
Diffstat (limited to '')
-rw-r--r--TODO.md3
-rwxr-xr-xanypinentry65
2 files changed, 39 insertions, 29 deletions
diff --git a/TODO.md b/TODO.md
index 2b27dac..4984790 100644
--- a/TODO.md
+++ b/TODO.md
@@ -2,6 +2,7 @@
- [X] Cli arg to set password prompt command
- [X] Cli arg to set confirmation prompt command
- [X] Add confirmation command
+ - [X] Add repeat password support
+ - [ ] Repeat error action
- [ ] Use text that is provided as commands
- - [ ] Add repeat password support
- [ ] Clear password support?
diff --git a/anypinentry b/anypinentry
index 13e7e26..01f8675 100755
--- a/anypinentry
+++ b/anypinentry
@@ -13,11 +13,13 @@ description="";
keyinfo="";
repeat="";
+AP_REPEAT_ERROR_STRING="Passwords don't match";
AP_YES="Yes";
AP_NO="No";
prompt_action='dmenu -P -p "$AP_PROMPT"';
confirm_action='echo -e "$AP_YES\n$AP_NO" | dmenu -p "$AP_PROMPT"';
+display_error_action='notify-send -a "Pinentry" "$AP_ERROR"';
# :: Prompt string (default if empty)
ask_password() {
@@ -30,6 +32,11 @@ confirm() {
export AP_YES; export AP_NO;
echo -n '' | bash -c "$confirm_action" 2> /dev/null;
}
+# :: Error text
+show_error() {
+ export AP_ERROR="$1";
+ bash -c "$display_error_action" 2> /dev/null;
+}
cancelled_error() { echo "ERR 99 Operation cancelled <Unspecified source>"; }
com_error() { echo "ERR 99 Operation cancelled <Unspecified source>"; }
@@ -59,6 +66,7 @@ password_prompt() {
# If password repeat attempt failed, try again,
# Else continue
if [[ ! -z "$2" ]] && [[ "$pass" != "$2" ]]; then
+ show_error "$AP_REPEAT_ERROR_STRING";
password_prompt "$repeat";
else
[[ ! -z "$pass" ]] && echo "D $pass";
@@ -82,18 +90,19 @@ interpret_command() {
# Case insensitive search
case "${cmd^^}" in
- INIT) echo "OK Pleased to meet you" ;;
- OPTION) save_option "$data" ;;
- GETINFO) get_info "$data" ;;
- SETTITLE) title="$data" && echo "OK" ;;
- SETPROMPT) prompt_string="$data" && echo "OK" ;;
- SETKEYINFO) keyinfo="$data" && echo "OK" ;;
- SETREPEAT) repeat="${data:-"repeat"}" && echo "OK" ;;
- SETDESC) description="$data" && echo "OK" ;;
- CONFIRM) confirm_prompt ;;
- GETPIN) password_prompt "$repeat" "" ;;
- BYE) echo "OK closing connection" && exit 0 ;;
- *) echo "OK" ;;
+ INIT) echo "OK Pleased to meet you" ;;
+ OPTION) save_option "$data" ;;
+ GETINFO) get_info "$data" ;;
+ SETTITLE) title="$data" && echo "OK" ;;
+ SETPROMPT) prompt_string="$data" && echo "OK" ;;
+ SETKEYINFO) keyinfo="$data" && echo "OK" ;;
+ SETREPEAT) repeat="${data:-"repeat"}" && echo "OK" ;;
+ SETDESC) description="$data" && echo "OK" ;;
+ SETREPEATERROR) AP_REPEAT_ERROR_STRING="$data" && echo "OK" ;;
+ CONFIRM) confirm_prompt ;;
+ GETPIN) password_prompt "$repeat" "" ;;
+ BYE) echo "OK closing connection" && exit 0 ;;
+ *) echo "OK" ;;
esac;
}
@@ -108,12 +117,13 @@ parse_cliargs() {
[[ $# -le 0 ]] && return 0;
case "$1" in
- -D|--display) export DISPLAY="$2"; shift 1 ;;
- --prompt) prompt_action="$2"; shift 1 ;;
- --confirm) confirm_action="$2"; shift 1 ;;
- -v|--version) echo "anypinentry-$VERSION" && exit 0 ;;
- -h|--help) help && exit 0 ;;
- *) help && exit 1 ;;
+ -D|--display) export DISPLAY="$2"; shift 1 ;;
+ --error-command) display_error_action="$2"; shift 1 ;;
+ --prompt) prompt_action="$2"; shift 1 ;;
+ --confirm) confirm_action="$2"; shift 1 ;;
+ -v|--version) echo "anypinentry-$VERSION" && exit 0 ;;
+ -h|--help) help && exit 0 ;;
+ *) help && exit 1 ;;
esac;
shift 1;
@@ -131,14 +141,13 @@ while read line; do
interpret_command "$line";
done;
- #{ "SETREPEATERROR", cmd_setrepeaterror },
- #{ "SETERROR", cmd_seterror },
- #{ "SETOK", cmd_setok },
- #{ "SETNOTOK", cmd_setnotok },
- #{ "SETCANCEL", cmd_setcancel },
- #{ "MESSAGE", cmd_message },
- #{ "SETQUALITYBAR", cmd_setqualitybar },
- #{ "SETQUALITYBAR_TT", cmd_setqualitybar_tt },
- #{ "SETTIMEOUT", cmd_settimeout },
- #{ "CLEARPASSPHRASE", cmd_clear_passphrase },
+# "SETERROR"
+# "SETOK"
+# "SETNOTOK"
+# "SETCANCEL"
+# "MESSAGE"
+# "SETQUALITYBAR"
+# "SETQUALITYBAR_TT"
+# "SETTIMEOUT"
+# "CLEARPASSPHRASE"