#!/bin/sh

# Toggle dropdown terminal windows.
# The first argument is the title of the window.
# The rest of it is the program/command to be run
# in the dropdown window.

name="$1"
class="dropdown"
title="dropdown_$name"
active="$(xdotool search --name "$title" | wc -l)"
shift

case "$TERMINAL" in
*st)
	classflag="-c"
	titleflag="-t"
	cmdflag="-e"
	;;
*alacritty)
	classflag="--class"
	titleflag="--title"
	cmdflag="--command"
	;;
 *foot)
	classflag="-a"
	titleflag="-T"
	cmdflag="-e"
esac

case "$active" in
0) $TERMINAL "$classflag" "dropdown" "$titleflag" "$title" "$cmdflag" "$@" & ;;
*) kill -9 "$(xdotool search --name "$class" getwindowpid)" ;;
esac