Experimental new code using getopt, it seems to work better, but who knows lol.
This commit is contained in:
parent
da6a960bcd
commit
cc1dab3fdb
57
ratatoskr.sh
57
ratatoskr.sh
@ -256,16 +256,6 @@ done
|
|||||||
# make sure the configuration and soundpack paths exist:
|
# make sure the configuration and soundpack paths exist:
|
||||||
mkdir -p "${configPath}/soundpacks"
|
mkdir -p "${configPath}/soundpacks"
|
||||||
|
|
||||||
# Keep track of the backgrounded loop
|
|
||||||
|
|
||||||
# Associative array of command line parameters and short description of what they do.
|
|
||||||
declare -A command=(
|
|
||||||
[C]="Recreate default configuration file. Acquire new oauth token."
|
|
||||||
[h]="Help, show usage information for ${0##*/}."
|
|
||||||
[M]="Post the currently playing music track, requires playerctl."
|
|
||||||
[p]="Post from the command line, e.g. ${0##*/} -p \"hello world\""
|
|
||||||
[S]="Scrobble the currently playing music track, requires playerctl."
|
|
||||||
)
|
|
||||||
|
|
||||||
# if the default file doesn't exist, create it
|
# if the default file doesn't exist, create it
|
||||||
if [[ ! -e "${configPath}/${configFile}" ]]; then
|
if [[ ! -e "${configPath}/${configFile}" ]]; then
|
||||||
@ -275,23 +265,48 @@ else
|
|||||||
source "${configPath}/${configFile}"
|
source "${configPath}/${configFile}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Associative array of command line parameters and short description of what they do.
|
||||||
|
declare -A command=(
|
||||||
|
[C]="Recreate default configuration file. Acquire new oauth token."
|
||||||
|
[h]="Help, show usage information for ${0##*/}."
|
||||||
|
[M]="Post the currently playing music track, requires playerctl."
|
||||||
|
[p::]="Post from the command line, e.g. ${0##*/} -p \"hello world\""
|
||||||
|
[S]="Scrobble the currently playing music track, requires playerctl."
|
||||||
|
)
|
||||||
|
|
||||||
# Handle command line parameters
|
# Handle command line parameters
|
||||||
# Convert the keys of the associative array to a format usable by getopts
|
# Convert the keys of the associative array to a format usable by getopt
|
||||||
args="${!command[*]}"
|
shortOptions="${!command[*]}"
|
||||||
args="${args//[[:space:]]/}"
|
shortOptions="${shortOptions//[[:space:]]/}"
|
||||||
while getopts "${args}" i ; do
|
|
||||||
case "$i" in
|
options="$(getopt -o "$shortOptions" -- "$@")"
|
||||||
C) get_oauth_token;;
|
|
||||||
h) help;;
|
while true; do
|
||||||
M)
|
case $1 in
|
||||||
|
-C)
|
||||||
|
get_oauth_token
|
||||||
|
shift;;
|
||||||
|
-h)
|
||||||
|
help
|
||||||
|
exit 0;;
|
||||||
|
-M)
|
||||||
post_music
|
post_music
|
||||||
exit 0;;
|
exit 0;;
|
||||||
p)
|
-p)
|
||||||
post_status "${OPTARG:-$(cat)}"
|
if [ -z "$2" ]; then
|
||||||
|
post_status "$(cat)"
|
||||||
|
else
|
||||||
|
shift
|
||||||
|
post_status "$@"
|
||||||
|
fi
|
||||||
exit 0;;
|
exit 0;;
|
||||||
S)
|
-S|--scrobble-music)
|
||||||
scrobble_music
|
scrobble_music
|
||||||
exit 0;;
|
exit 0;;
|
||||||
|
*)
|
||||||
|
# unexpected option
|
||||||
|
help
|
||||||
|
exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user