tardis: uset getopts for argument handling - bitreich-tardis - Front-end for navigating bitreich memes and TV dimensions
(HTM) git clone git://bitreich.org/bitreich-tardis git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/bitreich-tardis
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Tags
(DIR) README
(DIR) LICENSE
---
(DIR) commit 82ecf51b8a3dd34f14841e293fbab24df5bed0df
(DIR) parent 80502121eeec5f4f5b5d128726fbd3199d8bf7db
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Sun, 21 Feb 2021 21:16:39 +0100
tardis: uset getopts for argument handling
Diffstat:
M tardis | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
---
(DIR) diff --git a/tardis b/tardis
@@ -12,6 +12,11 @@ TARDIS_DMENU=${TARDIS_DMENU:-"dmenu -l 10 -p ${0##*/}:"}
TARDIS_PLUMB=${TARDIS_PLUMB:-xdg-open}
TARDIS_VIDEO=${TARDIS_VIDEO:-mpv}
+usage() {
+ printf 'usage: %s [-cu]\n' "${0##*/}" 1>&2
+ exit 1
+}
+
update() {
cd "$annna" && git pull >/dev/null
getdimensions
@@ -37,10 +42,17 @@ init() {
}
init
-
-if test "$1" = "-u"; then
- update
- exit 0
+clip=""
+while getopts uc arg; do
+ case ${arg} in
+ u) update; exit 0 ;;
+ c) clip=1 ;;
+ *) usage ;;
+ esac
+done
+shift $((OPTIND - 1))
+if test $# != 0; then
+ usage
fi
meme="$( (printf '%s\n%s\n' "$updatestr" "$interludestr"; \
@@ -51,12 +63,12 @@ elif test "$meme" = "$interludestr"; then
${TARDIS_PLUMB} ssh://time-machine@bitreich.org
elif test "$meme"; then
if printf '%s\n' "$meme" | grep -qE '\.m3u$'; then
- if test "$1" = "-c"; then
+ if test "$clip"; then
printf '%s' "${meme}" | xclip -i
fi
${TARDIS_VIDEO} "$meme"
else
- if test "$1" = "-c"; then
+ if test "$clip"; then
printf '%s' "${meme% *}" | xclip -i
printf '%s' "${meme#* }" | xclip -i -selection clipboard
fi