Beginnings of the command parser added.

This commit is contained in:
stormdragon2976 2023-01-30 19:36:42 -05:00
parent ebad002e73
commit ae0cc60a79
1 changed files with 36 additions and 1 deletions

View File

@ -3,6 +3,15 @@
# Hopefully one day this will be a full featured Pleroma client.
# 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.
help() {
echo "${0##*/}"
@ -181,6 +190,9 @@ done
# make sure the configuration and soundpack paths exist:
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.
declare -A command=(
[C]="Recreate default configuration file. Acquire new oauth token."
@ -219,8 +231,11 @@ while getopts "${args}" i ; do
done
# Main loop
# Main loops
# Display timelines and requested information.
while : ; do
# Important, set bgLoop to 1 or this loop will not close with the program
bgLoop=1
if [[ -n "${since_id}" ]]; then
result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/va/timelines/${timeline:-home}?since_id=${since_id}")"
else
@ -257,6 +272,26 @@ while : ; do
fi
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