dotfiles

.local/bin/bspc-toggle [raw] [blame]
 1#!/usr/bin/env bash
 2#
 3# Toggle hidden on an X11 window
 4
 5usage() {
 6  echo $0 --class CLASS
 7}
 8
 9while [[ "$#" -gt 0 ]]; do
10  if [ "$1" = "--class" ]; then
11    class=$2
12    shift
13  elif [ "$1" = "--run" ]; then
14    # command to run, if no windows are found
15    run=$2
16    shift
17  else
18    echo "Invalid argument $1"
19    exit 1
20  fi
21
22  shift
23done
24
25if [ -z "$class" ]; then
26  usage
27  exit 1
28fi
29
30windows=$(xdotool search --classname $class)
31
32if [ -z "$windows" ]; then
33  if [ -n "$run" ]; then
34    $run &
35    sleep 0.3
36    windows=$(xdotool search --classname $class)
37  fi
38fi
39
40for window in $windows; do
41  bspc node $window --flag hidden -f
42done
43
44wait