tarch-configs/configs/bspwm/polybar/launch.sh
Andrey Zimin 1b1b70daed add nvim
2024-03-10 13:30:59 +03:00

65 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Files and Directories #
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
BAR="Chad WM"
POLYBAR_DIR="$HOME/.config/bspwm/polybar"
SFILE="${POLYBAR_DIR}/utils/system"
# Get system variable values for various modules #
GET_VALUES() {
CARD=$(light -L | grep 'backlight' | head -n1 | cut -d'/' -f3)
BATTERY=$(upower -i `upower -e | grep 'BAT'` | grep 'native-path' | cut -d':' -f2 | tr -d '[:blank:]')
ADAPTER=$(upower -i `upower -e | grep 'AC'` | grep 'native-path' | cut -d':' -f2 | tr -d '[:blank:]')
INTERFACE=$(ip link | awk '/state UP/ {print $2}' | tr -d :)
}
# Write values to `system` file #
SET_VALUES() {
if [[ "$ADAPTER" ]]; then
sed -i -e "s/adapter = .*/adapter = $ADAPTER/g" "${SFILE}"
fi
if [[ "$BATTERY" ]]; then
sed -i -e "s/battery = .*/battery = $BATTERY/g" "${SFILE}"
fi
if [[ "$CARD" ]]; then
sed -i -e "s/graphics_card = .*/graphics_card = $CARD/g" "${SFILE}"
fi
if [[ "$INTERFACE" ]]; then
sed -i -e "s/network_interface = .*/network_interface = $INTERFACE/g" "${SFILE}"
fi
}
# Launch Polybar with the selected style ONLY in the primary display #
LAUNCH_SINGLE_BAR() {
CARD=$(light -L | grep 'backlight' | head -n1 | cut -d'/' -f3)
INTERFACE=$(ip link | awk '/state UP/ {print $2}' | tr -d :)
if [[ -z "$CARD" ]]; then
sed -i -e 's/backlight/bna/g' "$DIR"/config
elif [[ "$CARD" != *"intel_"* ]]; then
sed -i -e 's/backlight/brightness/g' "$DIR"/config
fi
# Close polybar #
killall -q polybar
# Wait until closing polybar #
while pgrep -u $UID -x polybar >/dev/null; do
sleep 1
done
# Launch polybar #
polybar -q main -c "$DIR"/config &
}
# Execute functions #
GET_VALUES
SET_VALUES
LAUNCH_SINGLE_BAR