#!/bin/zsh

if [ $# -eq 0 ];then
  echo "Give at least a classname to toggle"
  exit 0
fi

name=$1
shift

if [ -z `xdotool search --classname $name` ];then
  bspc subscribe node_add -c 1 | cut -d ' ' -f 5 > /tmp/${name}_win &
  kitty --name $name $*
  sleep .5
else
  win=`cat /tmp/${name}_win`
  if [ -z `bspc query -N -n ${win}.hidden` ];then
    bspc node ${win} -g hidden
  else
    bspc node ${win} -g hidden -f
  fi
fi
