From 41c4a34544e0f028a675ef436b8983702f2971a6 Mon Sep 17 00:00:00 2001 From: cronyakatsuki Date: Fri, 27 May 2022 17:32:44 +0200 Subject: [PATCH] Better empty handling. --- dmenu-games | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/dmenu-games b/dmenu-games index 72d5148..c8cdf05 100755 --- a/dmenu-games +++ b/dmenu-games @@ -2,19 +2,31 @@ # dmenu script to open up my games -list=$( game-run --list categories | dmenu -p "Choose game category:") +get_category () { + category=$( game-run --list categories | dmenu -p "Choose game category:") -[ -z "$list" ] && exit 0 + [ -z "$category" ] && exit 0 +} -if [ -z "$1" ]; then - game=$(game-run --list $list | sed '/-18+/d' | dmenu -p "Choose game to run:") -elif [ "$1" = "-a" ]; then - game=$(game-run --list $list | dmenu -p "Choose game to run:") +get_category + +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 + + [ -z "$game" ] && get_category +done + +if game-run "$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" ] && exit 0 - -game-run "$game"