-
Notifications
You must be signed in to change notification settings - Fork 2
/
clean_ws_names.spell
executable file
·30 lines (26 loc) · 1.03 KB
/
clean_ws_names.spell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# I sometimes rename my workspaces, this resets the name when the ws is empty.
# Supports bspwm and herbstluftwm
until pgrep bspwm || pgrep herbstluftwm &>/dev/null; do sleep 1m; done
sleep 1m
bspc subscribe desktop_focus |
while read -r _; do
bspc wm -d |
jq '.monitors | map(.desktops) | flatten | map(select(.root == null)) | map([.id, .name]) | .[] | @csv' -r |
sed -E 's/,"([0-9]+).*"/,\1/' |
while IFS=',' read -r id name; do
bspc desktop "$id" --rename "$name" --layout tiled
done
done
hc=herbstclient
while read -r _; do
focused="tags.$($hc attr tags.focus.index)"
for t in $($hc foreach T tags. echo T | grep -P 'tags.[0-9]+'); do
name="$(("$($hc attr "$t.index")" + 1))"
[[ "$t" != "$focused" ]] &&
[[ "$($hc attr "$t.client_count")" -eq 0 ]] &&
[[ "$($hc attr "$t.name")" != "$name" ]] &&
echo "Cleaning $t" &&
$hc attr "$t.name" "$name"
done
done < <($hc -i focus_changed)