From ca968c4e5040f1ff4b5b5e12d9312360d807dcc1 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Mon, 3 Jun 2024 19:56:39 +0800 Subject: added submodules, change . -> dot (see man stow --dotfiles) --- dot-config/polybar/launch.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 dot-config/polybar/launch.sh (limited to 'dot-config/polybar/launch.sh') diff --git a/dot-config/polybar/launch.sh b/dot-config/polybar/launch.sh new file mode 100755 index 00000000..b53112df --- /dev/null +++ b/dot-config/polybar/launch.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +CARD="$(light -L | grep 'backlight' | head -n1 | cut -d'/' -f3)" +INTERFACE="$(ip link | awk '/state UP/ {print $2}' | tr -d :)" +RFILE="$DIR/.module" + +# Fix backlight and network modules +fix_modules() { + if [[ -z "$CARD" ]]; then + sed -i -e 's/backlight/bna/g' "$DIR"/config.ini + elif [[ "$CARD" != *"intel_"* ]]; then + sed -i -e 's/backlight/brightness/g' "$DIR"/config.ini + fi + + if [[ "$INTERFACE" == e* ]]; then + sed -i -e 's/network/ethernet/g' "$DIR"/config.ini + fi +} + +# Launch the bar +launch_bar() { + # Terminate already running bar instances + #killall -q polybar + if pgrep polybar > /dev/null; then + polybar-msg cmd restart + elif ! pgrep polybar > /dev/null; then + + # Wait until the processes have been shut down + while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done + + # Launch the bar + for mon in $(polybar --list-monitors | cut -d":" -f1); do + MONITOR=$mon polybar -q main -c "$DIR"/config.ini & + done + else + echo "An error had occured" + fi +} + +# Execute functions +if [[ ! -f "$RFILE" ]]; then + fix_modules + touch "$RFILE" +fi +launch_bar -- cgit v1.2.3