diff --git a/_config/polybar/launch.sh b/_config/polybar/launch.sh index e418e15..35ef7fa 100755 --- a/_config/polybar/launch.sh +++ b/_config/polybar/launch.sh @@ -5,13 +5,26 @@ POLYBAR_CONFIG=$(dirname $0)/config killall -q polybar while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done +displays=($(xrandr --listactivemonitors | tail -n +2 | awk '{ print $2 }')) + # display 'primary' bar on primary display and 'secondary' bar on all other displays -for display in $(xrandr --listactivemonitors | tail -n +2 | awk '{ print$2 }'); do - display=${display:1} # discard leading '+' - isprimary=$(expr match ${display} '^\*') # is this the primary display? - if [[ $isprimary -eq 1 ]]; then - MONITOR="${display:1}" polybar primary -r --config-file=${POLYBAR_CONFIG} & - else - MONITOR="$display" polybar secondary -r --config-file=${POLYBAR_CONFIG} & +for display in ${displays[@]}; do + # discard leading '+' + display=${display:1} + + # If display name begins with '*' (primary) or only one display is available + isprimary=0 + if [ $(expr match ${display} '^\*') -eq 1 ] || [ ${#displays[@]} -eq 1 ]; then + isprimary=1 fi + + # Choose appropriate configuration depending whether or not this is a primary display + [ $isprimary -eq 1 ] && config='primary' || config='secondary' + + # Clean up the display name + display=${display#"*"} # discard leading '*' if present + + echo $display $isprimary $config + # Launch polybar! + MONITOR=${display} polybar ${config} -r --config-file=${POLYBAR_CONFIG} & done