Dunst: using environment variables in ~/.config/dunstrc

Created on 8 Dec 2018  ·  6Comments  ·  Source: dunst-project/dunst

I would like to set colors of notifications based on environment variables. Instead of:

~/.config/dunst/dunstrc:

[urgency_low]
    # IMPORTANT: colors have to be defined in quotation marks.
    # Otherwise the "#" and following would be interpreted as a comment.
    background = "#222222"
    foreground = "#888888"
    timeout = 5

I would like to do:

~/.config/dunst/dunstrc:

[urgency_low]
    # IMPORTANT: colors have to be defined in quotation marks.
    # Otherwise the "#" and following would be interpreted as a comment.
    background = "${DUNST_NORMAL_BACKGROUND}"
    foreground = "${DUNST_NORMAL_FOREGROUND}"
    timeout = 5

Set these environment variables in ~/.profile, or whichever file is sourced that sets environment variables that can be picked up by dunst.

~/.profile:

DUNST_NORMAL_BACKGROUND="#888888"
DUNST_NORMAL_FOREGROUND="#FFFFFF"

So that when I load dunst via `~/.config/i3/config

exec --no-startup-id dunst

Then dunst will set colors of notifications based off of what is set in ~/.profile
I would like to centralize the themes (colors mostly) across all my applications that use config files (i3, polybar, rofi, dunst, termite, etc). My goal is to have a single file to set env vars in so that i can swap out themes by sourcing a single file.

I want to take themes similar to this and apply theme across several applications.
https://github.com/arcticicestudio/nord

Most helpful comment

Well, for simple variable substitution, you could use simply the envsubst command:

envsubst < ~/.config/dunst/dunstrc.template > ~/.config/dunst/dunstrc

All 6 comments

As you may have guessed this is not currently possible and I'm not sure about implementing it.

However, have you looked into the contrib directory? We have a script that generates a dunstrc from Xresource values, you could either use that or somehow adapt it to use shell variables

@tsipinakis I was not aware of that script. I ran it and swapped the file it created for the original file and it changed dunsts colors, which is helpful. After a quick read through it I do not understand what values it expects to read from Xresources when determining which settings to overwrite. I will continue to read it until it makes sense.

I wish that dunst either supported environment variables or importing configs into the main config. The script is a good idea though, I'll give it a shot.

I'm trying to create a desktop environment comprised of tools that are keyboard driven and use config files for configuration, that is easy to configure in one location. Themeing is one of the few things left on my list to solve. You can see the source code here if you're interested! :)

Well, for simple variable substitution, you could use simply the envsubst command:

envsubst < ~/.config/dunst/dunstrc.template > ~/.config/dunst/dunstrc

@bebehei wow I had no idea that existed. That's amazing! Thank you for that suggestion!

So, I think the obvious solution is to use envsubst. For any other values, please consult #357

@bebehei Awesome! Thanks.
I'm using this now:

#~/.xinitrc

#Use bash instead of sh so we can use bashisms
if [[ x"$BASH" != x"/bin/bash" ]]; then
  exec /bin/bash "$HOME/.xinitrc"
fi
dunst -config <(envsubst < ~/.config/dunst/dunstrc) &
Was this page helpful?
0 / 5 - 0 ratings