Made scripts more readable by moving most logic to functions.

This commit is contained in:
cronyakatsuki 2022-11-04 14:54:08 +01:00
parent 86e3a3a79c
commit 5c738fdc77
11 changed files with 234 additions and 133 deletions

View file

@ -1,8 +1,9 @@
#!/bin/sh
# dmenu script to open up my games
. $HOME/.config/dmenu/config
load_config () {
. $HOME/.config/dmenu/config
}
get_category () {
category=$( game-run list | $DMENU -p "Choose game category:")
@ -10,25 +11,39 @@ get_category () {
[ -z "$category" ] && exit 0
}
get_category
menu () {
while [ -z "$game" ]
do
while [ -z "$game" ]
do
if [ -z "$1" ]; then
game=$(game-run list "$category" | sed '/-18+/d' | $DMENU -p "Choose game to run:")
elif [ "$1" = "-a" ]; then
game=$(game-run list "$category" | $DMENU -p "Choose game to run:")
else
printf '%s\n' "Option $1 doesn't exit!!"
exit 1
fi
if [ -z "$1" ]; then
game=$(game-run list "$category" | sed '/-18+/d' | $DMENU -p "Choose game to run:")
elif [ "$1" = "-a" ]; then
game=$(game-run list "$category" | $DMENU -p "Choose game to run:")
[ -z "$game" ] && get_category
done
}
launch_game () {
if game-run launch "$game"; then
quick-notify "Game run" "Launching $game"
else
printf '%s\n' "Option $1 doesn't exit!!"
exit 1
quick-notify "Game run" "Failed to launch $game"
fi
}
[ -z "$game" ] && get_category
done
main () {
load_config
if game-run launch "$game"; then
quick-notify "Game run" "Launching $game"
else
quick-notify "Game run" "Failed to launch $game"
fi
get_category
menu
launch_game
}
main $@