Beginnings of the command parser added.

This commit is contained in:
stormdragon2976 2023-01-30 19:36:42 -05:00
parent ebad002e73
commit ae0cc60a79

View File

@ -3,6 +3,15 @@
# Hopefully one day this will be a full featured Pleroma client. # Hopefully one day this will be a full featured Pleroma client.
# Let's see how far we can get. :) # Let's see how far we can get. :)
# Handle subprocesses that may not close with the main program.
trap cleanup EXIT
cleanup() {
if [[ $bgLoop -ne 0 ]]; then
trap 'pkill -P $$' EXIT
fi
}
# Display usage information. # Display usage information.
help() { help() {
echo "${0##*/}" echo "${0##*/}"
@ -181,6 +190,9 @@ 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
bgLoop=0
# Associative array of command line parameters and short description of what they do. # Associative array of command line parameters and short description of what they do.
declare -A command=( declare -A command=(
[C]="Recreate default configuration file. Acquire new oauth token." [C]="Recreate default configuration file. Acquire new oauth token."
@ -219,8 +231,11 @@ while getopts "${args}" i ; do
done done
# Main loop # Main loops
# Display timelines and requested information.
while : ; do while : ; do
# Important, set bgLoop to 1 or this loop will not close with the program
bgLoop=1
if [[ -n "${since_id}" ]]; then if [[ -n "${since_id}" ]]; then
result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/va/timelines/${timeline:-home}?since_id=${since_id}")" result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/va/timelines/${timeline:-home}?since_id=${since_id}")"
else else
@ -257,6 +272,26 @@ while : ; do
fi fi
sleep "${interval:-300}" sleep "${interval:-300}"
done &
# Handle commands
while : ; do
# Command prompt:
read -er -p "<${softwareName}> " command
if [[ ! "${command}" =~ ^/ ]]; then
post_status "${command}"
continue
fi
case "${command}" in
"/exit"|"/quit")
exit 0
;;
*)
systemMessage="Error: '${command}' is not a valid command."
play_sound error
;;
esac
done done