#!/bin/sh
set -eu

# A dedicated app-id lets Hyprland distinguish Nocal from ordinary terminal
# windows. NOCAL_TERMINAL may be set to one executable path (without arguments).
if [ "${NOCAL_TERMINAL:-}" != "" ]; then
    exec "$NOCAL_TERMINAL" -e nocal "$@"
fi

if command -v kitty >/dev/null 2>&1; then
    exec kitty --class nocal --name nocal --title Nocal nocal "$@"
elif command -v foot >/dev/null 2>&1; then
    exec foot --app-id=nocal --title=Nocal nocal "$@"
elif command -v wezterm >/dev/null 2>&1; then
    exec wezterm start --class nocal -- nocal "$@"
elif command -v alacritty >/dev/null 2>&1; then
    exec alacritty --class nocal,Nocal --title Nocal -e nocal "$@"
elif command -v xdg-terminal-exec >/dev/null 2>&1; then
    exec xdg-terminal-exec nocal "$@"
elif [ "${TERMINAL:-}" != "" ]; then
    exec "$TERMINAL" -e nocal "$@"
fi

printf '%s\n' 'nocal: no supported terminal emulator found' >&2
exit 127
