[pass] [PATCH 2/3] passmenu: Use getopt to process options

Emil Lundberg lundberg.emil at gmail.com
Sat Jul 25 18:21:36 CEST 2015


---
 contrib/dmenu/passmenu | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 9b5239d..34653a8 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -2,11 +2,17 @@
 
 shopt -s nullglob globstar
 
+PROGRAM="${0##*/}"
+
 typeit=0
-if [[ $1 == "--type" ]]; then
-	typeit=1
-	shift
-fi
+
+opts="$(getopt -o "" -l typeit -n "$PROGRAM" -- "$@")"
+[[ $? -ne 0 ]] && (echo "Usage: $PROGRAM [--typeit]" >&2 ; exit 1)
+eval set -- "$opts"
+while true; do case $1 in
+	--typeit) typeit=1; shift ;;
+	--) shift; break ;;
+esac done
 
 prefix=${PASSWORD_STORE_DIR-~/.password-store}
 password_files=( "$prefix"/**/*.gpg )
-- 
2.4.6



More information about the Password-Store mailing list