Skip to content

Instantly share code, notes, and snippets.

@useredsa
Created October 28, 2020 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save useredsa/14adab034e8b76f6f77fb8b4aeac6195 to your computer and use it in GitHub Desktop.
Save useredsa/14adab034e8b76f6f77fb8b4aeac6195 to your computer and use it in GitHub Desktop.
Playing with bspwm
#!/bin/sh
# Ideas:
# Use receptacles because they spawn automatically and
# preselections are limited to one per node
#
# 1. Create receptacle and add a rule
# 2. Run command that launches window
# 3. Do whatever with the window id (like storing it in a file)
#
# Saveguards:
# Wait until rule doesn't conflict with other rules #TODO
# General timeout -> delete receptacle and rule #TODO
# Receptacle disappears -> delete rule
# Rule disappears -> delete receptacle #TODO
# Catch general failures in commands #TODO
if [ $# != 3 -a $# != 4 ]; then
cat <<EOF
Usage: $(basename "${0}") <rule_filter> <launch_cmd> <output_cmd> [<location>]
Input:
rule_filer
A string that "bspc rule --add" could receive.
For example, the classname of the application.
launch_cmd
Shell command to launch the application
output_cmd
Command that will be called like \$output_cmd \$node,
where \$node is the id of the spawned window.
Defaults are sensible.
location
A string that bspc node --insert-receptacle could receive.
It can be used to set the position of the new receptacle.
EOF
exit 1
fi
rule_filter="$1:"
launch_cmd="$2"
output_cmd="$3"
position="$4"
export cname="${rule_filter%%:*}"
rest="${rule_filter#*:}"
iname="${rest%%:*}"
export iname="${iname:-*}"
bspc node $position --insert-receptacle
export receptacle=$(bspc query --nodes --node @brother)
bspc rule --add "$rule_filter" --one-shot hidden=on
$launch_cmd < /dev/null > /dev/null 2>&1 &
bspc subscribe node_add node_transfer |
while read d0 d1 d2 d3 d4 d5 d6; do
if [ $d0 = node_add ]; then
# node_add <monitor_id> <desktop_id> <ip_id> <node_id>
node=$d4
if bspc query --nodes --node $node.hidden > /dev/null ; then
ncname=$(bspc query -T -n $node | jq -c '.client | .className')
niname=$(bspc query -T -n $node | jq -c '.client | .instanceName')
if [ "$cname" = "*" -o "\"$cname\"" = "$ncname" ] &&
[ "$iname" = "*" -o "\"$iname\"" = "$niname" ]; then
bspc node $node -n $receptacle --flag hidden=off
$output_cmd $node
break
fi
fi
else
# node_transfer <src_monitor_id> <src_desktop_id> <src_node_id>
# <dst_monitor_id> <dst_desktop_id> <dst_node_id>
dst_node=$d6
if [ $dst_node = $receptacle ]; then
bspc rule --remove "$cname" --one-shot hidden=on
break
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment