#!/bin/sh

# dmenu script to open up my games

source $HOME/.config/dmenu/config

get_category () {
    category=$( game-run list | $DMENU -p "Choose game category:")

    [ -z "$category" ] && exit 0
}

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 launch "$game"; then
    quick-notify "Game run" "Launching $game"
else
    quick-notify "Game run" "Failed to launch $game"
fi