Skip to content

Instantly share code, notes, and snippets.

@nephitejnf
Last active April 19, 2023 17:45
Show Gist options
  • Save nephitejnf/4b2bb4b6deddbebf7b4706e8960165f4 to your computer and use it in GitHub Desktop.
Save nephitejnf/4b2bb4b6deddbebf7b4706e8960165f4 to your computer and use it in GitHub Desktop.
A dmenu script for running doom WADs with various source ports (some of the more popular)
#!/bin/sh
#
# 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.
neutral_background="#02280f"
neutral_font_color="#911c14"
selected_background="#b22318"
fontface="TerminessTTF Nerd Font:style=Bold:size=16"
## End of themeing
# These directories are where all the data is
# I separate PWADs and IWADs for scripting convenience and to do some
# half-way decent sorting
PWAD_START=1
IWAD_DIR="${HOME}/.config/doomenu/iwads/"
PWAD_DIR="${HOME}/.config/doomenu/pwads/"
## TODO
###
# Handling for chocolate/crispy derivatives
# Chocolate Doom/Heretic/Hexen/Strife/Chex
# Crispy Doom
SOURCE_PORTS=("gzdoom" "qzdoom" "zdoom" "prboom" "prboom-plus" "chocolate-doom" "crispy-doom" "zandronum")
SOURCE_PORT=""
SKIP_RUN=0
#IWAD=$(echo -e "Cancel\n$(ls ${IWAD_DIR})" | dmenu -nb "${neutral_background}" -nf "${neutral_font_color}" -sb "${selected_background}" -fn "${fontface}" -i -p "Select IWAD")
IWAD=""
PWAD=("")
# For some reason we need a way to pick a PWAD, so here's the first part of the process
SelectPwad () {
d=0
i=0
# If we want to pick multiple PWADS, then we have the option to, thanks to looping
while [ $d -lt 1 ]
do
# Pipe our ls and extra options into dmenu
PWADI=$(echo -e "Done\nCancel\n$(ls ${PWAD_DIR})" | dmenu -nb "${neutral_background}" -nf "${neutral_font_color}" -sb "${selected_background}" -fn "${fontface}" -i -p "Select PWAD (Done to finish, Cancel to Abort)")
# case statements might work better here instead, but it works
if [ $PWADI == "Done" ]; then
echo "Done"
d=1
elif [ $PWADI == "Cancel" ]; then
echo "Cancel"
break
else
PWAD[$i]="${PWADI}"
i=`expr 1 + $i`
fi
done
# We gotta add a '-file' argument for each PWAD we chose
PWADS=""
for p in "${PWAD[@]}"; do
PWADS="${PWADS} -file ${PWAD_DIR}$p"
done
echo $PWADS
# the above is merely for debugging purposes
# below is our final command, for this run
${SOURCE_PORT} -iwad ${IWAD_DIR}${IWAD} ${PWADS}
}
# I supported arguments, so then we had the option of skipping a step
# if we knew what we wanted, there are of course some limitations depending
# on the WADs and or source ports you pick
#
# Order is immaterial
# The only thing that you can't use arguments for like this is PWADs
for arg in "$@"; do
case $arg in
"gzdoom") SOURCE_PORT="gzdoom";;
"qzdoom") SOURCE_PORT="qzdoom";;
"zdoom") SOURCE_PORT="zdoom";;
"zandronum") SOURCE_PORT="zandronum";;
"crispy") SOURCE_PORT="crispy-doom";;
"chocolate") SOURCE_PORT="chocolate";;
"prboom") SOURCE_PORT="prboom";;
"prboom-plus") SOURCE_PORT="prboom-plus";;
"nopwad") PWAD_START=0;;
"freedoom1") IWAD="freedoom1.wad";;
"freedoom2") IWAD="freedoom2.wad";;
"freedm") IWAD="freedm.wad";;
"doom") IWAD="DOOM.WAD";;
"doom2") IWAD="DOOM2.WAD";;
"tnt"|"evilution") IWAD="tnt.wad";;
"plutonia") IWAD="plutonia.wad";;
"strife") IWAD="strife1.wad";;
"strifeve") IWAD="SVE.wad";;
"heretic") IWAD="HERETIC.WAD";;
"hexen") IWAD="HEXEN.WAD";;
"hexdd") IWAD="HEXDD.WAD";;
"chex3") IWAD="chex3.wad";;
"chex2") IWAD="CHEX2.WAD";;
"chex") IWAD="chex.wad";;
"hacx") IWAD="hacx.wad";;
"harmony") IWAD="harm1.wad";;
"rekkr") IWAD="rekkrsa.wad";;
"help")
echo "usage: doomenu [SOURCE_PORT] [IWAD] [nopwad]"
echo "Options:"
echo ""
echo "SOURCE_PORT options:"
echo " prboom, prboom-plus PRBoom ports"
echo " gzdoom, qzdoom, zdoom ZDoom ports"
echo " chocolate Chocolate ports"
echo " crispy Crispy Doom port"
echo ""
echo "IWAD options:"
echo " doom, doom2, tnt, evilution, plutonia Doom (1, 2, Evilution, Project Plutonia)"
echo " strife, strifeve Strife (Demo, Veteran's Edition)"
echo " heretic Heretic"
echo " freedoom1, freedoom2, freedm Freedoom (Phase 1, 2, Deathmatch)"
echo " hexen, hexdd Hexen"
echo " chex3 Chex Quest"
echo " hacx"
echo " harmony"
echo ""
echo "Misc Options:"
echo " nopwad Skip PWAD select"
echo " help Show this stuff"
SKIP_RUN=1
PWAD_START=0
;;
*) echo "No option for $arg";;
esac
done
# Hopefully the help display is pretty clear
# If we don't have a source port given to us, then we check what ones we have
# After we find the ones available, we simply print out a list
# Oh, and it pipes that list into dmenu for choosing
#
# This is a trick I stole from SXMO on the Pinephone
if [ "$SOURCE_PORT" == "" ] && [ $SKIP_RUN -lt 1 ]; then
PORT_LIST=""
for port in "${SOURCE_PORTS[@]}"; do
case $port in
"gzdoom") [ -x "$(command -v ${port})" ] && PORT_LIST="${PORT_LIST}\ngzdoom";;
"qzdoom") [ -x "$(command -v ${port})" ] && PORT_LIST="${PORT_LIST}\nqzdoom";;
"zdoom") [ -x "$(command -v ${port})" ] && PORT_LIST="${PORT_LIST}\nzdoom";;
"prboom") [ -x "$(command -v ${port})" ] && PORT_LIST="${PORT_LIST}\nprboom";;
"prboom-plus") [ -x "$(command -v ${port})" ] && PORT_LIST="${PORT_LIST}\nprboom-plus";;
"zandronum") [ -x "$(command -v ${port})" ] && PORT_LIST="${PORT_LIST}\nzandronum";;
"chocolate-doom") [ -x "$(command -v ${port})" ] && PORT_LIST="${PORT_LIST}\nchocolate";;
"crispy-doom") [ -x "$(command -v ${port})" ] && PORT_LIST="${PORT_LIST}\ncrispy-doom";;
*) echo -e "Nothing";;
esac
done
SOURCE_PORT=$(echo -e "$PORT_LIST" | dmenu -nb "${neutral_background}" -nf "${neutral_font_color}" -sb "${selected_background}" -fn "${fontface}" -i -p "Which source port?" -l 6)
fi
# If we never chose an IWAD, then we choose one here
# Most options are pretty standard, so that is why IWADs have arguments
[ "$IWAD" == "" ] && IWAD=$(echo -e "Cancel\n$(ls ${IWAD_DIR})" | dmenu -nb "${neutral_background}" -nf "${neutral_font_color}" -sb "${selected_background}" -fn "${fontface}" -i -p "Select IWAD")
# This one is important for making sure our sourceport and IWAD match
# Some source ports have different binaries based on the game
# Look at chocolate or crispy, due to different game engine mechanics in
# DOOM, Heretic, Hexen, and Strife, each has a separate binary
#
# GZDOOM is special in that so much is programmed into it and so it only needs
# one and supports the wider options for PWADs as well
#
# PRBOOM is pretty much just doom, sad, but okay
if [ "$SOURCE_PORT" != "" ]; then
if [ "$SOURCE_PORT" == "chocolate" ]; then
case $IWAD in
"DOOM.WAD"|"DOOM2.WAD"|"DOOMGBA.WAD"|"freedoom1.wad"|"freedoom2.wad"|"freedm.wad"|"HACX.WAD"|"rekkrsa.wad") SOURCE_PORT="chocolate-doom";;
"strife1.wad"|"SVE.wad") SOURCE_PORT="chocolate-strife";;
"HERETIC.WAD"|"BLASPHEM.WAD"|"blasphem.wad") SOURCE_PORT="chocolate-heretic";;
"HEXEN.WAD"|"HEXDD.WAD") SOURCE_PORT="chocolate-hexen";;
*) SKIP_RUN=1 && notify-send "Invalid WAD for chocolate ports";;
esac
elif [ "$SOURCE_PORT" == "crispy-doom" ]; then
case $IWAD in
"DOOM.WAD"|"DOOM2.WAD"|"DOOMGBA.WAD"|"freedoom1.wad"|"freedoom2.wad"|"freedm.wad"|"HACX.WAD"|"rekkrsa.wad") SOURCE_PORT="crispy-doom";;
"HERETIC.WAD"|"BLASPHEM.WAD"|"blasphem.wad") SOURCE_PORT="crispy-heretic";;
"HEXEN.WAD"|"HEXDD.WAD") SOURCE_PORT="crispy-hexen";;
*) SKIP_RUN=1 && notify-send "Invalid WAD for crispy experience";;
esac
elif [ "$SOURCE_PORT" == "prboom"] || [ "$SOURCE_PORT" == "prboom-plus" ]; then
case $IWAD in
"DOOM.WAD"|"DOOM2.WAD"|"DOOMGBA.WAD"|"freedoom1.wad"|"freedoom2.wad"|"freedm.wad"|"HACX.WAD"|"rekkrsa.wad") echo "Okay WAD for Crispiness";;
*) SKIP_RUN=1 && notify-send "Invalid WAD for prboom experience";;
esac
fi
fi
# We first check if we feel like playing with PWADs this time around
# if not, it will skip choosing a PWAD
if [ "$IWAD" != "Cancel" ] && [ "$IWAD" != "" ]; then
[ "$PWAD_START" != 0 ] && PWAD_CONFIRM=$(echo -e "Yes\nNo" | dmenu -nb "${neutral_background}" -nf "${neutral_font_color}" -sb "${selected_background}" -fn "${fontface}" -i -p "Use PWADs?" -l 2)
if [ "$PWAD_CONFIRM" == "Yes" ]; then
SelectPwad
elif [ "$PWAD_CONFIRM" == "No" ] || [ $PWAD_START == 0 ]; then
[ $SKIP_RUN -lt 1 ] && ${SOURCE_PORT} -iwad ${IWAD_DIR}${IWAD}
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment