#!/usr/bin/env bash

# This is a bash script that toggles otter-launcher with foot terminal.
# Modify foot --app-id to others, for example alacritty --class, if you use other emulators.
# When run, otter-launcher will be launched if not already running, be focused if running but not being focused, and be closed when already running and focused.

if [ -z $(swaymsg -t get_tree | grep '"app_id": "otter-launcher"') ] 
then
    foot --app-id "otter-launcher" -T "otter-launcher" -e sh -c "sleep 0.01 && otter-launcher"
else
    if [ -z $(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).app_id' | grep "otter-launcher") ];
	then
	    swaymsg [app_id="^otter-launcher$"] focus;
	else
	    swaymsg [app_id="^otter-launcher$"] kill;
    fi
fi
