bspwm: Stop using expr where I don't have to

This commit is contained in:
Salt 2018-08-22 11:10:32 -05:00
parent ea107552cd
commit f4dd3e2bb3

View File

@ -13,7 +13,7 @@ monitors_secondary=($(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{
desktops_total=${BSPWM_DESKTOPS_TOTAL:-8} desktops_total=${BSPWM_DESKTOPS_TOTAL:-8}
desktops_primary=${BSPWM_DESKTOPS_PRIMARY:-6} desktops_primary=${BSPWM_DESKTOPS_PRIMARY:-6}
desktops_secondary=$(expr $desktops_total - $desktops_primary) desktops_secondary=$(($desktops_total - $desktops_primary))
# Sanity checks # Sanity checks
if ! [[ "$desktops_total" -ge 1 ]]; then if ! [[ "$desktops_total" -ge 1 ]]; then
@ -31,7 +31,7 @@ if [[ $desktops_secondary -lt ${#monitors_secondary[@]} ]]; then
printf " [WARN] Configuration would leave some monitors without desktops!\n" 1>&2 printf " [WARN] Configuration would leave some monitors without desktops!\n" 1>&2
printf " [INFO] Adding more desktops\n" printf " [INFO] Adding more desktops\n"
desktops_secondary=${#monitors_secondary[@]} desktops_secondary=${#monitors_secondary[@]}
desktops_total=$(expr $desktops_secondary + $desktops_primary) desktops_total=$(($desktops_secondary + $desktops_primary))
deskpermon=1 deskpermon=1
printf " [INFO] Remaining desktops set to $desktops_secondary, highest desktop is now $desktops_total\n" printf " [INFO] Remaining desktops set to $desktops_secondary, highest desktop is now $desktops_total\n"
fi fi
@ -39,9 +39,9 @@ fi
# Can we actually reach all of these desktops via keybinds? # Can we actually reach all of these desktops via keybinds?
if [[ $desktops_total -gt 10 ]]; then if [[ $desktops_total -gt 10 ]]; then
printf " [WARN] More than ten desktops were allocated! Not all of these can be reached via keybinds!\n" 1>&2 printf " [WARN] More than ten desktops were allocated! Not all of these can be reached via keybinds!\n" 1>&2
if [[ $(expr $desktops_total - $desktops_secondary) -gt 0 ]]; then if [[ $(($desktops_total - $desktops_secondary)) -gt 0 ]]; then
printf " [INFO] Adjusting primary desktop reservation\n" printf " [INFO] Adjusting primary desktop reservation\n"
desktops_primary=$(expr $desktops_total - $desktops_secondary) desktops_primary=$(($desktops_total - $desktops_secondary))
printf " [INFO] Set reserved desktops to $desktops_primary\n" printf " [INFO] Set reserved desktops to $desktops_primary\n"
else else
printf " [WARN] Cannot resolve this situation without starving the primary monitor of desktops!\n" printf " [WARN] Cannot resolve this situation without starving the primary monitor of desktops!\n"
@ -58,14 +58,14 @@ if [[ $(echo ${monitors_secondary:-0}) == "0" ]]; then
printf " [INFO] Found one monitor: $monitor_primary, so giving it layout \"$layout\"\n" printf " [INFO] Found one monitor: $monitor_primary, so giving it layout \"$layout\"\n"
bspc monitor $monitor_primary -d $layout bspc monitor $monitor_primary -d $layout
else else
deskpermon=$(expr $desktops_secondary / ${#monitors_secondary[@]}) deskpermon=$(($desktops_secondary / ${#monitors_secondary[@]}))
layout=$(seq --separator=" " 1 $desktops_primary) layout=$(seq --separator=" " 1 $desktops_primary)
printf " [INFO] Giving primary monitor $monitor_primary layout \"$layout\"\n" printf " [INFO] Giving primary monitor $monitor_primary layout \"$layout\"\n"
bspc monitor $monitor_primary -d $layout bspc monitor $monitor_primary -d $layout
unset layout unset layout
printf " [INFO] Attempting to put $desktops_secondary desktops across ${#monitors_secondary[@]} monitors, $deskpermon each\n" printf " [INFO] Attempting to put $desktops_secondary desktops across ${#monitors_secondary[@]} monitors, $deskpermon each\n"
for m in $(seq 0 $(expr ${#monitors_secondary[@]} - 1)); do for m in $(seq 0 $((${#monitors_secondary[@]} - 1))); do
layout=$(seq --separator=" " $(expr 1 + $m + $desktops_primary) ${#monitors_secondary[@]} $(expr $desktops_total )) layout=$(seq --separator=" " $((1 + $m + $desktops_primary)) ${#monitors_secondary[@]} "$desktops_total")
printf " [INFO] Giving monitor $m (${monitors_secondary[$m]}) layout \"$layout\"\n" printf " [INFO] Giving monitor $m (${monitors_secondary[$m]}) layout \"$layout\"\n"
bspc monitor ${monitors_secondary[$m]} -d $layout bspc monitor ${monitors_secondary[$m]} -d $layout
done done