QsDoomLauncher.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. #
  3. # Q's Doom Launcher v0.1
  4. #
  5. # A simple WAD & mod selector script for launching GZDoom via rofi/dmenu
  6. #
  7. # IWADs should all be stored in 1 directory, and all mods in another.
  8. #----------------
  9. # CONFIG OPTIONS
  10. #----------------
  11. #
  12. # This section holds variables to be edited for each user install
  13. # Directory containing IWAD files
  14. IWAD_DIR="$HOME/Games/Doom/"
  15. ## Ensure trailing slashes for the directory paths
  16. # Directory containing mod files (*.wad/*.pk3 only supported at present)
  17. MOD_DIR="$HOME/Games/Doom/Mods/"
  18. ## Ensure trailing slashes for the directory paths
  19. # Display option for separator
  20. SEPERATOR="-----"
  21. # Menu system to use - valid options are "rofi" or "dmenu" - defaults to dmenu
  22. MENU_SYSTEM="rofi"
  23. # Set a prefix command to run before launching, for example optirun for optimus setups
  24. PREFIX_COMMAND=""
  25. #-----------------
  26. # Set menu system
  27. #-----------------
  28. #
  29. # This section will setup the menu system to use (either rofi or dmenu)
  30. # Allow this script to define & use aliases
  31. shopt -s expand_aliases
  32. # Create an alias "DisplayMenu" to match format from chosen menu system
  33. if [ $MENU_SYSTEM = rofi ]; then
  34. echo Using rofi
  35. alias DisplayMenu="rofi -dmenu"
  36. else
  37. echo Using dmenu
  38. alias DisplayMenu="dmenu -l 25"
  39. fi
  40. #-------------
  41. # Select IWAD
  42. #-------------
  43. #
  44. # Selection process for base WAD for the play through
  45. # Generate list of all IWAD files
  46. IWADLIST=$(ls $IWAD_DIR | grep -i 'wad$')
  47. # Select IWAD from list
  48. BASEWAD=$(printf '%s\n' "$IWADLIST" | DisplayMenu -p "Base IWAD")
  49. #-------------
  50. # Select Mods
  51. #-------------
  52. #
  53. # Selection process for mod(s) to be used
  54. # Generate list of PK3/WAD Mod files
  55. MODLIST=$(ls $MOD_DIR | grep -i -e 'wad$' -e 'pk3$')
  56. # Variable FINISHED_SELECTION tracks when user has selected "done" to break the loop
  57. FINISHED_SELECTION=1
  58. # Variable containing list of all selected mods
  59. RUNNINGMODS=""
  60. while [ $FINISHED_SELECTION -gt 0 ]; do
  61. # Send modlist to dmenu
  62. SELECTEDMOD=$(printf '%s\n' "Done" "$SEPERATOR" "$MODLIST" "$SEPERATOR" "Reset" | DisplayMenu -p "Modifications")
  63. if [ $SELECTEDMOD = Done ]; then # Done
  64. # Break from loop
  65. FINISHED_SELECTION=0
  66. elif [ $SELECTEDMOD = Reset ]; then # Reset
  67. # Regenerate modlist, and clear running mods
  68. MODLIST=$(ls $MOD_DIR | grep -i -e 'wad$' -e 'pk3$')
  69. RUNNINGMODS=""
  70. elif [ $SELECTEDMOD = $SEPERATOR ]; then # Separator
  71. # Ensure loop will continue
  72. FINISHED_SELECTION=1
  73. elif [ -z $SELECTEDMOD ]; then # No option returned by dmenu
  74. # Ensure loop continues, in case of dmenu issue (such as Esc key being pressed)
  75. FINISHED_SELECTION=1
  76. elif [ -n $SELECTEDMOD ]; then # Any non-zero output from dmenu, assumed to be a mod file selected
  77. # Add full path to mod to the running mods list
  78. RUNNINGMODS="$MOD_DIR$SELECTEDMOD $RUNNINGMODS"
  79. # Adjust the modlist to show a signifier against any chosen mods
  80. MODLIST=$(printf '%s\n' $MODLIST | sed s/$SELECTEDMOD/[+]$SELECTEDMOD/)
  81. else
  82. # Report issues if dmenu output is something unexpected
  83. echo Something has gone wrong...
  84. fi
  85. done
  86. #---------------
  87. # Launch GZDoom
  88. #---------------
  89. #
  90. # Launch doom with all selected details
  91. $PREFIX_COMMAND gzdoom -iwad $IWAD_DIR$BASEWAD -file $RUNNINGMODS