2018-04-03 15:55:41 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
echo "Launching polybar"
|
|
|
|
|
2018-08-22 23:58:43 +02:00
|
|
|
LOGDIR="$HOME/.log/my-i3-desktop"
|
2018-05-01 15:46:04 +02:00
|
|
|
mkdir -p "$LOGDIR"
|
2018-08-22 23:58:43 +02:00
|
|
|
INIT_LOG="$LOGDIR/polybar-launch.log"
|
2018-05-01 15:46:04 +02:00
|
|
|
exec 1>&- 2>&-
|
|
|
|
exec 1>"$INIT_LOG" 2>&1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
detect_primary_monitor() {
|
|
|
|
primary="$(xrandr | grep -F " connected primary" | head -n1 | cut -d ' ' -f1)"
|
|
|
|
[[ -n $primary ]] || primary="$(echo "$monitors" | grep " connected" | head -n1 | cut -d ' ' -f1)"
|
|
|
|
echo "$primary"
|
|
|
|
}
|
|
|
|
|
2018-05-01 16:08:03 +02:00
|
|
|
echo -e "Determining primary monitor..."
|
2018-05-01 15:46:04 +02:00
|
|
|
primary=$(detect_primary_monitor)
|
|
|
|
[[ -n $primary ]] || { echo "WARNING: no primary monitor detected!"; notify-send -a "Polybar launcher" "No primary monitor detected" "Couldn't detect primary monitor. Check $INIT_LOG."; }
|
|
|
|
echo "Primary monitor: $primary"
|
|
|
|
|
|
|
|
echo -e "\nDetermining secondary monitors..."
|
|
|
|
secondary="$(xrandr --listmonitors | sed -n "1d;/$primary\$/d;"'s/^.* \([^ ][^ ]*\)$/\1/p')"
|
2018-05-01 16:15:49 +02:00
|
|
|
if [[ -n $secondary ]]; then
|
|
|
|
echo "Secondary monitors:"; echo "$secondary" | sed -r 's/^/* /'
|
|
|
|
else
|
|
|
|
echo "No secondary monitors."
|
|
|
|
fi
|
2018-05-01 15:46:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-03 15:55:41 +02:00
|
|
|
# Terminate already running bar instances
|
2018-05-01 15:46:04 +02:00
|
|
|
echo -e "\nTerminating already running bars..."
|
|
|
|
echo "Running Polybar processes:"
|
|
|
|
pgrep -u $UID -x polybar | sed -r 's/^/* /'
|
|
|
|
|
2018-04-03 15:55:41 +02:00
|
|
|
killall -q polybar
|
|
|
|
|
|
|
|
# Wait until the processes have been shut down
|
|
|
|
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
|
2018-05-01 15:46:04 +02:00
|
|
|
echo "Terminated."
|
|
|
|
|
2018-04-17 15:34:06 +02:00
|
|
|
(
|
2018-05-01 15:46:04 +02:00
|
|
|
echo -e "\nReading secrets..."
|
2018-04-17 15:34:06 +02:00
|
|
|
set -o allexport # Make all assignments exports
|
|
|
|
source "$(dirname "$0")"/secrets.sh
|
|
|
|
set +o allexport
|
|
|
|
|
2018-05-01 15:46:04 +02:00
|
|
|
echo
|
2018-04-30 16:54:11 +02:00
|
|
|
|
2018-05-01 15:46:04 +02:00
|
|
|
start_polybar() {
|
|
|
|
echo "Starting $1 on $2"
|
|
|
|
MONITOR="$2" \
|
|
|
|
polybar --config="$HOME/.config/polybar/config.ini" "$1" \
|
|
|
|
&>"$LOGDIR/$1-$2.log" & disown
|
|
|
|
}
|
|
|
|
|
|
|
|
start_polybar midbard "$primary"
|
|
|
|
|
2018-05-01 16:15:49 +02:00
|
|
|
if [[ -n $secondary ]]; then
|
|
|
|
while read -r monitor; do
|
|
|
|
start_polybar secondary "$monitor"
|
|
|
|
done <<< "$secondary"
|
|
|
|
fi
|
2018-04-17 15:34:06 +02:00
|
|
|
)
|
2018-04-03 15:55:41 +02:00
|
|
|
|
2018-05-01 15:46:04 +02:00
|
|
|
exec 1>&- 2>&-
|
|
|
|
|
2018-04-03 15:55:41 +02:00
|
|
|
echo "Polybar launched."
|