#!/bin/sh set -eu real_xterm() { local OLDIFS OLDIFS="$IFS" IFS=: local SELF SELF="$(realpath $0)" local CMD CMD="${SELF##*/}" for p in $PATH; do IFS="$OLDIFS" case "$SELF" in $p/*) continue ;; esac if [ -x "$p/$CMD" ]; then echo "$p/$CMD" return 0 fi done return 127 } xterm=$(real_xterm) kitty_args() { # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1103770 local arg rest=0 local args="--single-instance --wait-for-single-instance-window-close" for arg in "$@"; do if [ $rest = 0 ]; then case "$arg" in -help | --help) echo $arg break ;; -name | -hold | -title) arg="-$arg" ;; -cd) arg="-d" ;; -e | --) rest=1 ;; esac fi args="$args $arg" done echo $args } case "$(readlink -f $xterm)" in */kitty) set -- $(kitty_args "$@") ;; esac exec $xterm "$@"