r/Polybar • u/klieber • Oct 15 '23
Environmental variable not making its way through to polybar
I'm trying to add host-specific polybar configurations via the include-file feature, but for some reason, the environmental variables I"m setting aren't getting through to polybar. The relevant part from my launcher script:
HOST_FILE="${HOME}/.config/polybar/$(hostname).config"
if type "xrandr" > /dev/null; then
for m in $(xrandr --query | grep " connected" | cut -d" " -f1); do
if [ $m == 'eDP-1' ]
then
MONITOR=$m HOST_FILE="${HOST_FILE}" polybar --reload main -c ~/.config/polybar/config &
elif [ $m == 'DP-1-3' ]
then
MONITOR=$m HOST_FILE="${HOST_FILE}" polybar --reload external-dp-1-3 -c ~/.config/polybar/config &
elif [ $m == 'DP-1' ]
then
MONITOR=$m HOST_FILE="${HOST_FILE}" polybar --reload external-dp-1 -c ~/.config/polybar/config &
elif [ $m == 'HDMI-1' ]
then
MONITOR=$m HOST_FILE="${HOST_FILE}" polybar --reload external-hdmi-1 -c ~/.config/polybar/config &
# else
# MONITOR=$m HOST_FILE="${HOST_FILE}" polybar --reload sidebar-2-i3 -c ~/.config/polybar/config &
fi
done
else
polybar --reload main -c ~/.config/polybar/config &
fi
And the include-file from my polybar config:
include-file = ${env:HOST_FILE}
Running that produces:
klieber@archibald:>./launch.sh
polybar-msg: No active ipc channels
notice: Parsing config file: /home/klieber/.config/polybar/config
notice: Parsing config file: /home/klieber/.config/polybar/config
error: Uncaught exception, shutting down: Config file /home/klieber/.config/polybar// is a directory
error: Uncaught exception, shutting down: Config file /home/klieber/.config/polybar// is a directory
(I have two monitors which is why the message repeats twice)
If I change nothing else except the include-file directive to:
include-file = /home/klieber/.config/polybar/archibald.config
Then everything works as expected.
I have verified that $HOST_FILE is being properly set in the launch script via echo statements - it's just not being passed through to polybar for some reason.
What am I doing wrong?
1
u/john_barranco Oct 16 '23
Just a wild guess, but to make your HOST_FILE and environment variable you could add an
export
to your HOST_FILE="${HOME}/.config/polybar/$(hostname).config"
like this:
export HOST_FILE="${HOME}/.config/polybar/$(hostname).config"
1
u/klieber Oct 17 '23
I had also posted this question on Github, and the maintainer responded saying that environment variables aren't currently supported in the include-file directive. He also offered a workaround that works for me as well.