diff --git a/ratatoskr.sh b/ratatoskr.sh index 08da983..de9d0bf 100755 --- a/ratatoskr.sh +++ b/ratatoskr.sh @@ -3,6 +3,22 @@ # Hopefully one day this will be a full featured Pleroma client. # Let's see how far we can get. :) +# Display usage information. +help() { + echo "${0##*/}" + echo "Released under the terms of the WTFPL License" + echo -e "Usage:\n" + echo "With no arguments, open the interactive client." + for i in "${!command[@]}" ; do + echo "-${i/:/ }: ${command[${i}]}" + done | sort + echo + echo "Configuration files can be found in ${configPath}" + echo + exit 0 +} + + # Get an oauth token get_oauth_token() { echo "Welcome to ${softwareName}!" @@ -22,7 +38,7 @@ get_oauth_token() { # Load the new variables from the configuration file source "${configPath}/${configFile}" # Create the url to get the oauth token - local url="${instanceURL}/oauth/authorize?client_id=${client_id}&redirect_uri=https://billy.wolfe.casa/ratatoskr-success.html&response_type=code&scope=read%20write%20follow%20push" + local url="${instanceURL}/oauth/authorize?client_id=${client_id}&redirect_uri=${redirectURI}&response_type=code&scope=read%20write%20follow%20push" echo "Please open the following url in your browser." echo "Copy the generated token, and paste it here, then press enter to continue." echo @@ -37,6 +53,15 @@ get_oauth_token() { } +# Functions that deal with posting. + +# Post music with -M flag +post_music() { + echo "Work in progress..." + exit 0 +} + + # Variable initialization configPath="${XDG_CONFIG_HOME:-$HOME/.config}/ratatoskr" # Path for settings, usually ~/.config/ratatoskr configFile="default.conf" # The default config file, eventually will support multiple accounts. @@ -48,9 +73,30 @@ softwareName="Ratatoskr" # The name of the client. # make sure the configuration path exists: mkdir -p "${configPath}" +# Associative array of command line parameters and short description of what they do. +declare -A command=( + [h]="Help, show usage information for ${0##*/}." + [M]="Post the currently playing music track, requires playerctl." +) + # if the default file doesn't exist, create it if [[ ! -e "${configPath}/${configFile}" ]]; then get_oauth_token +else + # Read configuration file + source "${configPath}/${configFile}" fi +# Handle command line parameters +# Convert the keys of the associative array to a format usable by getopts +args="${!command[*]}" +args="${args//[[:space:]]/}" +while getopts "${args}" i ; do + case "$i" in + h) help;; + M) post_music;; + esac +done + + exit 0