2020-02-01 18:04:39 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-04-12 13:09:54 -07:00
|
|
|
# Toggle a scratch terminal window. A scratch terminal is a disposable terminal
|
|
|
|
# for one-off, quick commands that don't warrant a dedicated terminal.
|
|
|
|
|
2020-02-01 18:04:39 -08:00
|
|
|
SCRID=scratch
|
2020-02-09 00:03:58 -08:00
|
|
|
CMD=${1:-'tmux new-session -A -s scratch -n scratch'}
|
2020-02-01 18:04:39 -08:00
|
|
|
focused=$(xdotool getactivewindow)
|
|
|
|
scratch=$(xdotool search --onlyvisible --classname $SCRID)
|
|
|
|
if [[ -n $scratch ]]; then
|
|
|
|
if [[ $focused == $scratch ]]; then
|
|
|
|
xdotool windowkill $scratch
|
|
|
|
else
|
|
|
|
xdotool windowactivate $scratch
|
|
|
|
fi
|
|
|
|
elif command -v urxvt >/dev/null; then
|
|
|
|
urxvt -name $SCRID \
|
2020-02-02 14:22:31 -08:00
|
|
|
-e $SHELL -c "$CMD"
|
2020-02-01 18:04:39 -08:00
|
|
|
elif command -v xst >/dev/null; then
|
|
|
|
xst -t $SCRID -n $SCRID -c $SCRID \
|
2020-02-02 14:22:31 -08:00
|
|
|
-f "$(xrdb -query | grep 'scratch\.font' | cut -f2)" \
|
|
|
|
-e $SHELL -c "$CMD"
|
2020-02-01 18:04:39 -08:00
|
|
|
else
|
|
|
|
>&2 echo "No shell to launch the scratch terminal with"
|
|
|
|
exit 1
|
|
|
|
fi
|