Initial commit.

This commit is contained in:
Storm Dragon 2023-12-13 18:14:11 -05:00
commit 35fa143b20
2 changed files with 123 additions and 0 deletions

14
LICENSE Normal file
View File

@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

109
tojam Executable file
View File

@ -0,0 +1,109 @@
#!/usr/bin/env bash
# Dialog accessibility
export DIALOGOPTS='--no-lines --visit-items'
# Functions
help() {
echo "${0##*/}"
echo -e "Released under the terms of the WTFPL License: http://www.wtfpl.net\n"
echo -e "Usage:\n"
echo "With no arguments, open recent servers list."
for i in "${!command[@]}" ; do
echo "-${i/:/ <parameter>}: ${command[${i}]}"
done | sort
exit 0
}
# Array of command line arguments
declare -A command=(
[c]="Configure ${0##*/}."
[h]="This help screen."
[T]="Dedication."
)
add_server() {
echo "Add server coming soon"
}
settings() {
echo "Settings coming soon"
}
# 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
c) echo "Coming soon" ;;
h) help ;;
T)
echo "For Tony, because he's awesome!"
exit 0
;;
esac
done
# Configuration stuff
config="${XDG_CONFIG_HOME:-${HOME}/.config}/tojam"
sessiondir="${HOME}/tojam-sessions"
mkdir -p "${config}"
mkdir -p "${sessiondir}"
if ! [[ -r "${config}/config" ]]; then
# Write initial config file
echo 'anonymous="true"' >> "${config}/config"
echo 'soundDriver="jack"' >> "${config}/config"
echo "userName='Tojam$(date '+%S')'" >> "${config}/config"
fi
source "${config}/config"
# Fix up username if anonymous is true
if [[ "${anonymous}" == "true" ]]; then
userName="anonymous:${userName}"
fi
declare -A servers=(
[Shark Tank]="sharktank.sytes.net:2050"
[Ninjamer 1]="ninjamer.com"
[Ninjamer 2]="ninjamer.com:2050"
[Ninjamer 3]="ninjamer.com:2051"
[Ninjamer 4]="ninjamer.com:2052"
$( [[ -r "${config}/servers.conf" ]] && source "${config}/servers.conf")
)
# Server menu
declare -a menuList
for i in "${!servers[@]}" ; do
menuList+=("${servers[$i]}" "${i}")
done
server="$(dialog --clear \
--backtitle "Tojam" \
--no-tags \
--extra-button \
--extra-label "Add Server" \
--ok-label "Connect" \
--cancel-label "Exit" \
--help-button \
--help-label "Settings" \
--menu "Select a Ninjam server" -1 -1 -1 "${menuList[@]}" --stdout)"
menuCode=$?
case ${menuCode} in
1) exit 0;;
2) settings;;
3) add_server;;
esac
ninjam="$(command -v cninjam 2> /dev/null)"
[[ ${#ninjam} -le 3 ]] && { echo "Could not find cninjam."; exit 1; }
$ninjam "${server}" -user "${userName}" -${soundDriver} -sessiondir "${sessiondir}"