Bspwm what if I don't like empty workspaces?

Hello everyone, don’t you feel annoyed sometimes when you close the last window of a workspace and then find yourself on a empty place?
Bspwm has a feature called “subscribe” just like i3wm that you can use to capture events on windows or desktops to do other stuff, so let’s use it here and in particular the node_remove event (see man bspc)
So this script will use this feature to redirect you on the last visited workspace or monitor when you close the last existing window of a workspace.

#!/bin/bash
# Never find yourself on empty desktop

# avoid running multiple instances
X=$(basename $0)
pids=($(pidof -x $X))

[[ ${#pids[@]} -gt 1 ]] && exit

bspc subscribe node_remove | \
    while read -r; do
        if [[ -z $(bspc query -N -n .local.focused) ]]; then
            for win in $(bspc query -N -n .leaf.local.!window); do
                bspc node "$win" -k
            done
            bspc desktop -f last.local.occupied \
            || bspc desktop -f last.occupied
        fi
    done &

So now launch it without the ampersand sign (it’s already in the script beside the done of the loop) because we need it to run all the time.

4 Likes

Great addition, thanks for sharing.