zellij icon indicating copy to clipboard operation
zellij copied to clipboard

Theme switching for active sessions via --theme option

Open adriancostin6 opened this issue 11 months ago • 3 comments

Currently, I use zellij options --theme $ZELLIJ_THEME to set the theme via the CLI when starting Zellij, where $ZELLIJ_THEME is an environment variable I define to point at one of the builtin themes.

I have two aliases for automating this:

alias zt='zellij options --theme $ZELLIJ_THEME'
alias za='zt --attach-to-session true --session-name'

I use these to spawn new sessions and attach to already existing sessions. What I would like to be able to do is to change the $ZELLIJ_THEME environment variable and have it propagate to already existing sessions.

From what I saw so far, if I change the environment variable and try to use the attach alias above, the session I attach to still has the old theme. I understand that the theme option overrides the configuration for the Zellij session upon startup, but it would be nice if it could do so upon attaching to an existing session as well, as to support this use-case.

I am not a rustling, but I am also willing to try and fix it myself if you can help point me to a place to start looking 👍

adriancostin6 avatar Dec 17 '24 08:12 adriancostin6

I thought I would be able to dynamically update the theme in an active session: in 4. Configuration, the the docs, it says:

Zellij actively watches for changes in the active configuration file. Most fields will be applied immediately without the need for a restart. Otherwise, this will be mentioned in the commentary of the relevant field.

The theme entry in the config is not flagged as requires restart, but it doesn't work still. When I change the setting in my config and save the file, nothing changes in the current session.

dedebenui avatar May 25 '25 14:05 dedebenui

When I change the setting in my config and save the file, nothing changes in the current session.

Works fine for me. I use sed to set it (however doesn't change no active sessions)

ArchieAtkinson avatar May 26 '25 17:05 ArchieAtkinson

I would also be interested in this, but via a command line arg insead of having to modify the config source file (as I version control that file along with other dotfiles).

jjmark15 avatar May 26 '25 20:05 jjmark15

I suggest adding the option to configure the opened sessions.

hsequeda avatar Jul 09 '25 14:07 hsequeda

The best solution I’ve found so far is to use sed on the config file when I want to change the theme. If I just want to refresh it, I simply touch the config file. Even if there are no actual changes, touching it still forces Zellij to reload the configuration and apply the theme change.


# Change Zellij theme
sed -i "s/theme \".*\"/theme \"$THEME\"/g" ~/.config/zellij/config.kdl

# Refresh Zellij configs
touch ~/.config/zellij/config.kdl

Kasui92 avatar Nov 10 '25 13:11 Kasui92

Update on my side. Problem stated in the description might be a bit confusing, since I am too dumb to use my shell properly.

As seen there, I set aliases and use an environment variable called ZELLIJ_THEME. At the time, my assumption was that if I change this variable, zellij will pick up on the new theme, but that is not how shell aliases work. I always ended up with the same value for ZELLIJ_THEME in the expanded alias.

A better approach and a fix to this problem would be to wrap zellij in a bash function that reads the theme from a file on the filesystem where I will set it based on the terminal theme. This solves my dumb alias expansion mistake and might also possibly solve the issue here. Will have to test it out and come back with some feedback.

adriancostin6 avatar Nov 13 '25 11:11 adriancostin6