This repository has been archived on 2024-09-01. You can view files and clone it, but cannot push or open issues or pull requests.
al-skel/home/bin/start-polybar

66 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
# Polybar launcher script written by Nathaniel Maia for use in ArchLabs
# Will launch bars depending on WM
# Can also be used to reload openbox session with [--reload] or [-r]
# I reccomend using al-polyzen to set up a session for each wm
# then ditching this method and adding the following line to your autostart
# sleep 1; al-polybar-session &
# Enter your bar names here (seperated by spaces) eg. BARS=(bar1 bar2...)
# This will be combined with window manager from WMS below eg. openbox-bar1, openbox-bar2...
# by default it is set up in WM-BAR naming format eg. i3-bar, openbox-bar, bspwm-bar....
BARS=(bar)
2017-12-02 01:06:11 -06:00
CONFIG=$HOME/.config/polybar/config
WMS=(bspwm i3 openbox xfce awesome)
############################################################################################
HELP="\nUSAGE:\n\tstart-polybar [OPTIONS]
\nOPTIONS:\n\t--reload, -r\tIf running in openbox, will reload the session
\t--help, -h\tPrint this usage message and exit
\n\tWith no options the script will stop and reload polybar"
2017-12-08 04:03:03 -06:00
# determine WM
for i in ${WMS[@]}; do
if [[ "$(wmctrl -m | grep -i name | awk '{print tolower($2)}')" == "$i" ]]; then
WM=$i && break
elif [[ "$(xprop -root -notype | grep "WM_NAME =" | tr -d '"' | awk '{print tolower($3)}')" == "$i" ]]; then
WM=$i && break
elif [[ "$(awk '{print tolower($0)}' <<< $XDG_CURRENT_DESKTOP)" == "$i" ]]; then
WM=$i && break
fi
done
2017-12-08 04:03:03 -06:00
# check if passed options
case "$@" in
*help|-h)
echo -e $HELP && exit 0
;;
*reload|-r)
2017-12-08 04:03:03 -06:00
if [[ "$WM" == "openbox" ]]; then
openbox --restart
al-compositor --restart && al-tint2restart
fi
;;
esac
2017-12-08 04:03:03 -06:00
# kill running bars
while [ "$(pidof polybar)" ]; do
pkill polybar && sleep 0.5
done
# launch bars
for bar in "${BARS[@]}"; do
polybar -r --config=$CONFIG ${WM}-$bar &
done
if [ "$(pidof polybar)" ]; then
echo "Bars launched..."
2017-12-08 04:03:03 -06:00
else
echo "Bars Failed to Launch"
fi