#!/usr/bin/env fish function arrange-desktops # spread desktops to monitors set monitors (bspc query --monitors --names) set desktops (bspc query --desktops --names | grep -P '\d') set monitor_count (count $monitors) set desktop_count (count $desktops) # make sure desktops are sufficent for all monitors if test $desktop_count -lt $monitor_count for i in (seq 1 9) if not bspc query --desktops $i bspc monitor --add-desktops $i set desktops $desktops $i set desktop_count (math "$desktop_count + 1") if test $desktop_count -ge $monitor_count break end end end end # sort desktops set desktops (echo $desktops | tr ' ' '\n' | sort) # spreading set dpm (math "ceil($desktop_count/$monitor_count)") for i in (seq $monitor_count) set start (math "(($i - 1) * $dpm) + 1") set end (math "$start + $dpm - 1") echo $start $end $desktops[$start..$end] for d in $desktops[$start..$end] bspc desktop $d --to-monitor $monitors[$i] end bspc monitor $monitors[$i] --reorder-desktops $desktops[$start..$end] end # remove non-digital desktop for desktop in (bspc query --desktops --names) if not string match -r '^[1-9]$' $desktop bspc desktop $desktop --remove end end end function watch while read $HOME/.config/polybar/launch.sh arrange-desktops end end function launch killall -q bspc bspc subscribe monitor_add monitor_remove | watch end switch "$argv[1]" case 'arrange' arrange-desktops case 'launch' launch case '*' $HOME/.config/bspwm/arrange-desktops arrange $HOME/.config/bspwm/arrange-desktops launch & end