aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Brubaker <jbru362@gmail.com>2022-06-03 13:40:46 -0400
committerJeremy Brubaker <jbru362@gmail.com>2022-06-03 13:43:24 -0400
commit0ae91ebe6e50d78f06b27eb6dfaf7648d97b9db4 (patch)
tree23cf62075f3a94e623aeabc511e7b39e870b9b9c
parent6d5aa310072b48cd5dc696946426d1d431258411 (diff)
downloadanypinentry-0ae91ebe6e50d78f06b27eb6dfaf7648d97b9db4.tar.gz
anypinentry-0ae91ebe6e50d78f06b27eb6dfaf7648d97b9db4.zip
Support all standard `pinentry` options
This is a first step to making `anypinentry` into a drop-in replacement for `pinentry-*` The options processing was changed to use `getopt(1)` which adds a dependency but also simplifies the options processing. Version number bumped to '0.1'
-rwxr-xr-xanypinentry52
1 files changed, 39 insertions, 13 deletions
diff --git a/anypinentry b/anypinentry
index f550be1..beb8df0 100755
--- a/anypinentry
+++ b/anypinentry
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
-VERSION="0.0";
+VERSION="0.1";
if [[ -z "$DISPLAY" ]]; then
DISPLAY=":1";
@@ -114,20 +114,46 @@ help() {
}
parse_cliargs() {
- [[ $# -le 0 ]] && return 0;
+ getopt -T
+ if [ "$?" -ne 4 ]; then
+ printf "Your version of getopt(1) is out of date\n" >&2
+ exit 1
+ fi
- case "$1" in
- -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;
+ TEMP=$(getopt -n "$0" -o dD:T:N:C:M:o:gWc:a:h \
+ --long debug,display:,ttyname:,ttytype:,lc-ctype:,lc-messages:,timeout:,no-global-grab,parent-wid,colors:,ttyalert:,prompt:,confirm:,error:,help,version \
+ -- "$@")
+
+ if [ $? -ne 0 ]; then
+ help
+ exit 1
+ fi
+
+ eval set -- "$TEMP"
+ unset TEMP
- shift 1;
- parse_cliargs "$@";
+ while true; do
+ case "$1" in
+ -d | --debug) shift ;;
+ -D | --display) shift 2 ;;
+ -T | --ttyname) shift 2 ;;
+ -N | --ttytype) shift 2 ;;
+ -C | --lc-ctype) shift 2 ;;
+ -M | --lc-messages) shift 2 ;;
+ -o | --timeout) shift 2 ;;
+ -g | --no-global-grab) shift ;;
+ -W | --parent-wid) shift ;;
+ -c | --colors) echo "colors=$2"; shift 2 ;;
+ -a | --ttyalert) shift 2 ;;
+ --error-command) display_error_action="$2"; shift 2 ;;
+ --prompt) prompt_action="$2"; shift 2 ;;
+ --confirm) confirm_action="$2"; shift 2 ;;
+ -h | --help) help && exit 0 ;;
+ --version) echo "anypinentry-$VERSION" && exit 0 ;;
+ --) shift; break ;;
+ *) ;;
+ esac
+ done
}