commit 35fa143b20df82ab643b9d89477807bd59b02ed2 Author: Storm Dragon Date: Wed Dec 13 18:14:11 2023 -0500 Initial commit. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ee7d6a5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + + 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. + diff --git a/tojam b/tojam new file mode 100755 index 0000000..fcb90ff --- /dev/null +++ b/tojam @@ -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/:/ }: ${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}"