factorimods: support for dmenu-like (rofi...)

This commit is contained in:
Pieds-Nus 2022-09-16 21:20:35 +00:00
parent a762fe780f
commit 1c4e7f3817

View File

@ -3,6 +3,8 @@
# Dependencies : you'll need a dmenu-like to run this script.
# On debian and debian-like distros (ubuntu, mint...), simply run:
# sudo apt install dmenu
# If you use something else than dmenu, edit the following line accordingly:
dmenu=dmenu
# Edit this line to meet your installation
factorio_dir="/DATA/Games/factorio"
@ -16,33 +18,33 @@ factorio_dir="/DATA/Games/factorio"
cd $factorio_dir/saves
#Ask the user to select a save
save=$(ls -t *.zip | grep -v autosave | rev | cut -d "." -f 2- | rev | dmenu -i -l 5 -p "Chose a save file: ")
save=$(ls -t *.zip | grep -v autosave | rev | cut -d "." -f 2- | rev | $dmenu -i -l 5 -p "Chose a save file: ")
test $? -ne 0 && echo "No save selected" && exit 1
echo $save
# If -r option is passed, replace the modlist of hte save with the latest modlist from factorio
if test "$1" = "-r" ; then
cp ../mods/mod-list.json mod-list.json_$save
modlist=$save
#Check if a modlist exists for that save
# Check if a modlist exists for that save
elif test -s "mod-list.json_$save" ; then
modlist=$save
else
#Otherwise, prompt to load another modlist
modlist=$(ls -t mod-list.json_* | cut -d "_" -f 2- | dmenu -p "No mod list found for savegame \"$save\". Select mod list from available: ")
# Otherwise, prompt to load another modlist
modlist=$(ls -t mod-list.json_* | cut -d "_" -f 2- | $dmenu -p "No mod list found for savegame \"$save\". Select mod list from available: ")
test $? -ne 0 && echo "No modlist selected" && exit 1
#And prompt to save it for later
echo -e "yes\nno" | dmenu -p "Save selected modlist for savegame $save ?" | grep -q "yes" && cp mod-list.json_$modlist mod-list.json_$save && modlist=$save
# And prompt to save it for later
echo -e "yes\nno" | $dmenu -p "Save selected modlist for savegame $save ?" | grep -q "yes" && cp mod-list.json_$modlist mod-list.json_$save && modlist=$save
fi
echo $modlist
#Link that modlist to the file read by factorio
# Link that modlist to the file read by factorio
ln -fs ../saves/mod-list.json_$modlist ../mods/mod-list.json
#Launch the game and the requested save
# Launch the game and the requested save
cd ..
echo "$factorio_dir/bin/x64/factorio --load-game $factorio_dir/saves/$save.zip"
$factorio_dir/bin/x64/factorio --load-game $factorio_dir/saves/$save.zip