feat: oshu-launcher

main
Tom MTT. 2 years ago
commit 8a2b868c8f

@ -0,0 +1,171 @@
#!/bin/bash
# Copyright 2022 Tom MTT <tom@heimdall.pm>
# This file is licensed under the 3-Clause BSD License.
# Please see 'oshu-launcher version' for more information.
# Shell options
set -euo pipefail
# Debug Mode
[ "${DEBUG+x}" ] && set -x
# Constants
PROGRAM="$(basename "$0")"
PADDING="$(printf "%-${#PROGRAM}s")"
VERSION="0.1.0"
AUTHORS="Tom MTT <tom@heimdall.pm>"
PREFIX="$HOME/.osu"
# Misc
CLEAR="\033[0m"
RED="\033[31m"
BLUE="\033[34m"
ERROR="${RED}Error${CLEAR}"
PS3="> "
die() {
echo -e "$PROGRAM: $ERROR: $1" >&2
shift
for text in "$@"
do
echo -e "$PADDING $text" >&2
done
exit 1
}
# Check dependencies and stuff
check_deps() {
type oshu > /dev/null 2>&1 || die "'oshu' not found." "Make sure it is installed and in your \$PATH."
type tree > /dev/null 2>&1 || die "'tree' not found." "Make sure it is installed and in your \$PATH."
}
# Display help page
cmd_help() {
cat <<EOF
oshu-launcher - a small menu for oshu
Usage: $PROGRAM [help|version|play|list]
Commands:
help display this help
version display software version and license
play play oshu
list list available beatmaps and variants
EOF
}
# Display software version and license
cmd_version() {
cat <<EOF
oshu-launcher - a small menu for oshu
- version $VERSION by $AUTHORS
Copyright 2022 Tom MTT <tom@heimdall.pm>
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
EOF
}
# Play a beatmap
cmd_play() {
while true
do
clear
cd "$PREFIX"
echo -e "${BLUE}Which beatmap?${CLEAR}"
select beatmap in *
do
[[ "$REPLY" = "q" ]] && exit
[[ -z "$beatmap" ]] && continue
clear
cd "$beatmap"
variants=()
for file in *.osu
do
variants+=("$(basename "$file" .osu)")
done
echo -e "${BLUE}Which variant?${CLEAR}"
select variant in "${variants[@]}"
do
[[ "$REPLY" = "q" ]] && exit
[[ -z "$variant" ]] && continue
oshu --pause "$variant.osu"
break
done
break
done
done
}
# List every beatmap and variants
cmd_list() {
tree -NCl --prune --noreport -P "*.osu" * | sed -E 's/\.osu(\x1B\[[0-9]+m)?( ->|$)/\1\2/g'
}
# Main function
main() {
# Change root folder
cd "$PREFIX"
# Convert long flags to short ones
for arg in "$@"; do
shift
case "$arg" in
"--help") set -- "$@" "-h" ;;
"--version") set -- "$@" "-V" ;;
*) set -- "$@" "$arg" ;;
esac
done
argument="${1-}"
# Parse arguments
case "$argument" in
"") cmd_play ;;
"-h") cmd_help ;;
"-V") cmd_version ;;
"-"*)
die "'$argument' is not a known parameter." \
"Run '$PROGRAM help' for a list of known parameters."
;;
*)
shift
if type "cmd_$argument" > /dev/null 2>&1
then
"cmd_$argument" "$@"
else
die "'$argument' is not a known subcommand." \
"Run '$PROGRAM help' for a list of known subcommands."
fi
;;
esac
}
check_deps
main "$@"
Loading…
Cancel
Save