Skip to content

Instantly share code, notes, and snippets.

@tangboshi
Last active March 23, 2020 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tangboshi/b571e8bbf88ffe9fc8c31926d09eda57 to your computer and use it in GitHub Desktop.
Save tangboshi/b571e8bbf88ffe9fc8c31926d09eda57 to your computer and use it in GitHub Desktop.
Convenient game launcher for Linux
#!/bin/bash
# For the ultimate convenience configure your system to launch this script with
# a shortcut, e.g. Super + L
# e.g. for gnome-terminal:
# gnome-terminal -e "bash -c 'export PATH=$PATH:/path/to/launcher.sh ; launcher.sh'"
# Explanation text for this launcher (enter help during execution)
function help
{
printf "\nOne command pattern is:\n"
printf "The first (optional) character denotes using primusrun (p), optirun (o) or standard (no prefix)\n"
printf "The second letter denotes native Steam (s), Playonlinux (p)\n"
printf "Should you enter something unrecognized by the script, your command is executed.\n\n"
printf "Other important commands:\n"
printf "showsource, shortcuts, exit.\n"
}
function startBumblebee
{
command -v bumblebeed || ( echo "Bumblebee daemon is required" && return )
bumblebee_active=$(systemctl status bumblebeed.service | grep Active | awk '{print $2}')
if [ "$bumblebee_active" != "active" ];
then
echo "Launching bumblebee daemon..."
sudo systemctl start bumblebeed.service &&
while [ "$bumblebee_active" != "active" ]
do
sleep 1
bumblebee_active=$(systemctl status bumblebeed.service | grep Active | awk '{print $2}')
echo "Bumblebee is activating... (hopefully)"
done
echo "Success! Bumblebee was activated!"
# In case bumblebeed.service was already active
else
echo "Nice, bumblebee was already active!"
fi
}
##### NOTICES ON HOW TO MODIFY AND FURTHER EXTEND THIS SCRIPT #####
# 1
# In case you're using playonlinux you can launch applications via playonlinux --run shortcut
# To find out about shortcuts simply execute ls ~/.PlayOnLinux/shortcuts
# ALTERNATIVE: use the launcher's built-in shortcuts command, which does the exact same.
#
# 2
# In case you are using a NVIDIA card make sure you have installed the bumblebee,
# bbswitch and nvidia. If I were you I'd AVOID sudo systemctl enable bumblebeed.service.
# On my system this led to a kernel freeze during startup, because at that time the NVIDIA card
# is not active...
# If you don't have a NVIDIA card remove all startBumblebee calls below!
function loop
{
printf "\n(launcher) "
read toLaunch
# If for some reason you don't need the length of your command, comment the next line
com_length=${#toLaunch};
# Start Bumblebee if pattern is matched, modify to your liking
if ( [[ $toLaunch == p* ]] || [[ $toLaunch == o* ]] ) && ( [[ ${toLaunch:2:1} == [[:upper:]] ]] || [[ "$com_length" -eq 2 ]] )
then
startBumblebee
fi
## Add >/dev/null if you don't want console output
## Add &>/dev/null if you also want to suppress error messages
## May not work depending on how output is generated...
case $toLaunch in
# Launch Steam
"ps")
primusrun steam & disown
;;
"os")
optirun steam & disown
;;
"s")
steam & disown
;;
# Launch PlayOnLinux
"pp")
primusrun playonlinux & disown
;;
"op")
optirun playonlinux & disown
;;
"p")
playonlinux & disown
;;
# Launch Steam32 or Steam64 from PlayOnLinux drive
"pSteam32")
primusrun playonlinux --run Steam32 -no-cef-sandbox & disown
;;
"pSteam64")
primusrun playonlinux --run Steam64 -no-cef-sandbox & disown
;;
"pMorrowind")
primusrun playonlinux --run Steam32 -no-cef-sandbox -applaunch 22320 & disown
;;
# Launch specific PlayOnLinux program (non-Steam applications)
"Emperor")
playonlinux --run Emperor & disown
;;
"Settlers4")
playonlinux --run "Siedler 4" & disown
;;
"pGW2")
# I moved the -dx9single -maploadinfo -bmp flags to PlayOnLinux
primusrun playonlinux --run "Guild Wars 2" & disown
;;
# Launch other programs
# "Raw" Wine example
"pGrimdawn")
export WINEPREFIX=~/0_wp/grimdawn
# Comment if the game fails to launch
export WINEDEBUG=-all
# Uncomment if you use nVidia drivers
export LD_PRELOAD="libpthread.so.0 libGL.so.1"
export __GL_THREADED_OPTIMISATIONS=1
export __GL_SYNC_TO_VBLANK=1
export __GL_YIELD="NOTHING"
primusrun wine "c:/program files (x86)/steam/steam.exe" -no-dwrite -applaunch 219990 & disown
wait
;;
##### Special commands for this launcher
# Display help
"help")
help
;;
# Clear out command line
"clear" | "reset")
reset
;;
# Show playonlinux shortcuts
"shortcuts")
ls ~/.PlayOnLinux/shortcuts
;;
# Show source
"showsource")
# replace with editor of your liking, e.g. vim, kate or atom
nano $0
;;
# Simply just start bumblebee
"bumblebee*" | "startBumblebee")
startBumblebee
;;
# Terminate launcher
"exit" | "quit")
exit
;;
*)
# Replace the following with $toLaunch & disown && exit if you don't want any prompt!
echo "This command is unknown to the launcher. Execute (y/n) - default yes ?"
read execute
if [ "$execute" == "n" ]
then
:
else
echo "Disown (y/n) - default no ?"
read disown
if [ "$disown" == "y" ]
then
$toLaunch & disown
else
$toLaunch
wait
fi
fi
;;
esac
}
function main
{
## Comment the following line if you don't use PlayOnLinux
## ... or want to see Wine errors
export POL_IgnoreWineErrors=True
echo "This is a launcher for gamers on Linux by Alexander Pastor."
echo "Enter a command to launch the desired application. Enter help for help."
while [ "$toLaunch" != "quit" ]
do
loop
done
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment