-
-
Save neeasade/7ea170074a126317769aa40a1599d3a3 to your computer and use it in GitHub Desktop.
bspwm tree visualiser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
# \ | |
exec jq -Crf "$0" -- "$@" | |
def children: | |
objects | | |
.path as $p | | |
(.firstChild | objects | .path = $p + "/1"), | |
(.secondChild | objects | .path = $p + "/2") | | |
select(has("id")); | |
def isInnerNode: | |
any(children; true); | |
def isNonVacantLeaf: | |
.vacant or isInnerNode | not; | |
def numberOfBranchesWithNonVacantLeaves: | |
[ children | select(any(recurse(children); isNonVacantLeaf)) ] | | |
length; | |
def pathString: | |
"@\(.path // "/")"; | |
def node: | |
"\t\(.id) \( | |
"[color=\( | |
if isInnerNode then | |
numberOfBranchesWithNonVacantLeaves | | |
if . == 0 then | |
"gray" # fully vacant inner node | |
elif . == 1 then | |
"yellow" # non-splitting inner node | |
else | |
empty # splitting inner node | |
end | |
elif .vacant then | |
"red" # vacant window | |
elif .client != null then | |
"green" # non-vacant window | |
else | |
"blue" # receptacle | |
end | |
)]", | |
"[label=<\( | |
[ | |
pathString, | |
( | |
select(numberOfBranchesWithNonVacantLeaves == 2) | | |
"\( | |
if .splitType == "vertical" then | |
"V" | |
else | |
"H" | |
end | |
):\(.splitRatio)" | |
), | |
.id, | |
( | |
select(isNonVacantLeaf).rectangle | | |
objects | | |
"\(.width)x\(.height)+\(.x)+\(.y)" | |
), | |
( | |
.client | | |
objects | | |
@json "\(.className):\(.instanceName)" | |
) | | |
@html | |
] | | |
join("<BR/>") | |
)>]", | |
"-> \(children.id | values)" | |
);"; | |
"digraph BSPTree {", | |
( | |
objects.root | | |
select(type == "object" and (.path | type | IN("string", "null"))) | | |
recurse(children) | | |
node | |
), | |
"}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
if [ "$#" -ge 2 ]; then | |
printf 'Too many arguments.\n' >&2 | |
exit 2 | |
fi | |
bspc query -T -d ${1+"$1"} | | |
awk ' | |
NR == 1 && "BSPSHOWTREE_FLOAT" in ENVIRON { | |
system("bspc rule -a \\* -o state=floating") | |
} | |
{ print | "bspdeskjson2dot | dot -Txlib" } | |
END { exit NR == 0 } | |
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
case $# in | |
0) | |
: "${BSPTREEUPDATEDOT_OUTFILE:=/tmp/bsptree_$$.dot}" | |
;; | |
1) | |
if [ -z "$1" ]; then | |
printf 'Invalid empty argument.\n' >&2 | |
exit 2 | |
fi | |
BSPTREEUPDATEDOT_OUTFILE=$1 | |
;; | |
*) | |
printf 'Too many arguments.\n' >&2 | |
exit 2 | |
esac | |
while | |
tree=$(bspc query -T -d) && | |
printf '%s\n' "$tree" | | |
bspdeskjson2dot > "$BSPTREEUPDATEDOT_OUTFILE" && | |
bspc subscribe -c 1 desktop node > /dev/null | |
do | |
: | |
done | |
# Now, you can open the output file with `dot -Txlib' and see the tree | |
# update live! :D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
case $# in | |
0) | |
: "${BSPTREEUPDATEPNG_OUTFILE:=/tmp/bsptree_$$.png}" | |
;; | |
1) | |
if [ -z "$1" ]; then | |
printf 'Invalid empty argument.\n' >&2 | |
exit 2 | |
fi | |
BSPTREEUPDATEPNG_OUTFILE=$1 | |
;; | |
*) | |
printf 'Too many arguments.\n' >&2 | |
exit 2 | |
esac | |
while | |
tree=$(bspc query -T -d) && | |
printf '%s\n' "$tree" | | |
bspdeskjson2dot | | |
dot -Tpng -o "$BSPTREEUPDATEPNG_OUTFILE" && | |
bspc subscribe -c 1 desktop node > /dev/null | |
do | |
: | |
done | |
# Now, you can open the output file in an image viewer and see the tree | |
# update live! :D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Visualise the bspwm tree of the focused desktop in the floating window | |
super + ctrl + t | |
BSPSHOWTREE_FLOAT= bspshowtree |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment