summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAyush Agarwal <ayush@fastmail.in>2021-09-08 00:11:19 +0530
committerAyush Agarwal <ayush@fastmail.in>2021-09-08 00:11:19 +0530
commitc1530dbf24d7a5203915706c584720d1ed9cd26a (patch)
treee1a0ddf6e6bae74170cc630467c7fe42d04d688f
parent683692a48b8b379e418062f4366c344c264b0996 (diff)
moved the getopts loop to the main function
There's no need to have the getopts loop outside the main function. The main function can be called as `main "$@"` to accept positional parameters as input which then goes on to `getopts` which, by default, uses `"$@"` unless a positional parameters is explicitly given.
-rwxr-xr-xtessen46
1 files changed, 24 insertions, 22 deletions
diff --git a/tessen b/tessen
index 577f0f8..d679084 100755
--- a/tessen
+++ b/tessen
@@ -25,27 +25,6 @@ BACKEND="bemenu"
CLIP_TIME=15
WTYPE=""
-while getopts ':hab:s:' opt; do
- case "$opt" in
- h)
- print_help
- exit 0
- ;;
- a) WTYPE=1 ;;
- b) BACKEND="$OPTARG" ;;
- s) CLIP_TIME="$OPTARG" ;;
- \?)
- notify-send "invalid option: -$OPTARG"
- exit 1
- ;;
- :)
- notify-send "option -$OPTARG requires a value"
- exit 1
- ;;
- esac
-done
-unset -v opt
-shift $((OPTIND - 1))
readonly CLIP_TIME
readonly BACKEND
@@ -234,6 +213,29 @@ clean() {
}
main() {
+ # parse any options given by the user
+ while getopts ':hab:s:' opt; do
+ case "$opt" in
+ h)
+ print_help
+ exit 0
+ ;;
+ a) WTYPE=1 ;;
+ b) BACKEND="$OPTARG" ;;
+ s) CLIP_TIME="$OPTARG" ;;
+ \?)
+ notify-send "invalid option: -$OPTARG"
+ exit 1
+ ;;
+ :)
+ notify-send "option -$OPTARG requires a value"
+ exit 1
+ ;;
+ esac
+ done
+ unset -v opt
+ shift $((OPTIND - 1))
+
get_pass_file
get_pass_data
@@ -246,4 +248,4 @@ main() {
fi
}
-main
+main "$@"