bspwm monitorset.sh: Fix division by zero, add sanity checks
This commit is contained in:
parent
d253c3daf1
commit
4861be0df0
@ -15,14 +15,24 @@ desktops_total=${BSPWM_DESKTOPS_TOTAL:-8}
|
||||
desktops_primary=${BSPWM_DESKTOPS_PRIMARY:-6}
|
||||
desktops_secondary=$(expr $desktops_total - $desktops_primary)
|
||||
|
||||
deskpermon=$(expr $desktops_secondary / ${#monitors_secondary[@]})
|
||||
printf " [INFO] Distributing $desktops_total desktops, $desktops_primary for primary and $desktops_secondary across all secondaries\n"
|
||||
# Sanity checks
|
||||
if ! [[ "$desktops_total" -ge 1 ]]; then
|
||||
printf " [ERROR] desktops_total cannot be $desktops_total, defaulting\n" 1>&2
|
||||
desktops_total=8
|
||||
fi
|
||||
if ! [[ "$desktops_primary" -ge 1 ]]; then
|
||||
printf " [ERROR] desktops_primary cannot be $desktops_primary, defaulting\n" 1>&2
|
||||
desktops_primary=6
|
||||
fi
|
||||
|
||||
# Setup
|
||||
if [[ $(echo ${monitors_secondary:-0}) == "0" ]]; then
|
||||
# We only have one monitor, so give it everything
|
||||
layout=$(seq --separator=" " 1 $desktops_total)
|
||||
printf " [INFO] Found one monitor: $monitor_primary, so giving it layout $layout\n"
|
||||
bspc monitor $monitor_primary -d $layout
|
||||
else
|
||||
deskpermon=$(expr $desktops_secondary / ${#monitors_secondary[@]})
|
||||
# Give the first monitor the first few workspaces
|
||||
layout=$(seq --separator=" " 1 $desktops_primary)
|
||||
printf " [INFO] Giving primary monitor $monitor_primary layout $layout\n"
|
||||
@ -33,8 +43,9 @@ else
|
||||
if [ $desktops_secondary -lt ${#monitors_secondary[@]} ]; then
|
||||
printf " [WARN] Configuration would leave some monitors without workspaces! Adding more\n"
|
||||
desktops_secondary=${#monitors_secondary[@]}
|
||||
desktops_total=$(expr $desktops_secondary + $desktops_primary)
|
||||
deskpermon=1
|
||||
printf " [INFO] Remaining workspaces set to $desktops_secondary\n"
|
||||
printf " [INFO] Remaining workspaces set to $desktops_secondary, highest workspace is now $desktops_total\n"
|
||||
fi
|
||||
# And distribute the rest to the secondaries
|
||||
for m in $(seq 0 $(expr ${#monitors_secondary[@]} - 1)); do
|
||||
@ -48,5 +59,4 @@ unset monitors_secondary
|
||||
unset desktops_total
|
||||
unset desktops_primary
|
||||
unset desktops_secondary
|
||||
unset deskpermon
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user