2019-06-24 04:44:48 -05:00
|
|
|
#! /bin/bash
|
|
|
|
#
|
|
|
|
# launch.sh
|
|
|
|
# A Polybar launch script with a heck of a lot of compat
|
|
|
|
# Copyright (C) 2019 Vintage Salt <rehashedsalt@cock.li>
|
|
|
|
#
|
|
|
|
# Distributed under terms of the MIT license.
|
|
|
|
#
|
|
|
|
|
2019-07-04 15:15:54 -05:00
|
|
|
log() {
|
|
|
|
[ -z "$1" ] && return 1
|
|
|
|
printf "$1\\n"
|
|
|
|
}
|
|
|
|
|
2019-06-24 04:44:48 -05:00
|
|
|
# Trap our exit
|
|
|
|
die() {
|
|
|
|
kill $(jobs -p)
|
|
|
|
}
|
|
|
|
trap die EXIT
|
|
|
|
|
|
|
|
# Steps
|
2019-06-29 21:44:03 -05:00
|
|
|
step_fallback() {
|
|
|
|
if ! command -v polybar > /dev/null 2>&1; then
|
|
|
|
if command -v tint2 > /dev/null 2>&1; then
|
2019-07-04 15:15:54 -05:00
|
|
|
log "Executing fallback"
|
2019-06-29 21:44:03 -05:00
|
|
|
exec tint2
|
|
|
|
fi
|
2019-07-04 15:15:54 -05:00
|
|
|
log "No valid bars found"
|
|
|
|
exit 51
|
2019-06-29 21:44:03 -05:00
|
|
|
fi
|
|
|
|
}
|
2019-06-24 04:44:48 -05:00
|
|
|
step_configure_restack() {
|
|
|
|
# Restack compatibility
|
|
|
|
if pgrep -U "$UID" bspwm > /dev/null 2>&1; then
|
|
|
|
export PB_WM_RESTACK="bspwm"
|
|
|
|
elif pgrep -U "$UID" i3 > /dev/null 2>&1; then
|
|
|
|
export PB_WM_RESTACK="i3"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
step_spawn_primary() {
|
|
|
|
# Spawn bars on the primary monitor
|
2019-07-04 15:15:54 -05:00
|
|
|
log "Spawning primary bars"
|
2019-06-24 04:44:48 -05:00
|
|
|
export PB_MONITOR=$(xrandr -q | awk '/primary/{print $1}')
|
|
|
|
polybar -r primary &
|
|
|
|
polybar -r primary-2 &
|
|
|
|
}
|
|
|
|
step_spawn_secondary() {
|
|
|
|
# Spawn more for each secondary
|
2019-07-04 15:15:54 -05:00
|
|
|
log "Spawning secondary bars"
|
2019-07-11 17:29:10 -05:00
|
|
|
local secondary_monitors=$(xrandr -q | grep ' connected' | grep -v 'primary' | awk '{print $1}')
|
|
|
|
[ -z "$secondary_monitors" ] && return 0
|
2019-06-24 04:44:48 -05:00
|
|
|
for monitor in $secondary_monitors; do
|
2019-07-11 17:29:10 -05:00
|
|
|
export PB_MONITOR=$monitor
|
2019-06-24 04:44:48 -05:00
|
|
|
polybar -r secondary &
|
|
|
|
polybar -r secondary-2 &
|
|
|
|
done
|
|
|
|
}
|
|
|
|
step_wait() {
|
|
|
|
# And wait
|
2019-07-04 15:15:54 -05:00
|
|
|
log "Waiting"
|
2019-06-24 04:44:48 -05:00
|
|
|
wait
|
|
|
|
}
|
|
|
|
|
|
|
|
# Main
|
|
|
|
main() {
|
2019-06-29 21:44:03 -05:00
|
|
|
step_fallback
|
2019-06-24 04:44:48 -05:00
|
|
|
step_configure_restack
|
|
|
|
step_spawn_primary
|
|
|
|
step_spawn_secondary
|
|
|
|
step_wait
|
|
|
|
}
|
|
|
|
|
|
|
|
main "$@"
|
|
|
|
|