1

I'm trying to make my tmux config a little more modular by abstracting the colors to a separate file. I'm sourcing that file and then using the variables defined there as my tmux theme:

# part of my tmux.conf:
source '~/.tmux/themes/gruvbox'

# status bar
set -g status "on"
set -g status-attr "none"
set -g status-justify "left"
set -g status-bg $TMUX_STATUS_BG

# status left
set -g status-left-attr "none"
set -g status-left-length "100"

# status right
set -g status-right-attr "none"
set -g status-right-length "100"

# window
setw -g window-status-attr "none"
setw -g window-status-separator ""
# this isn't picked up
setw -g window-status-format "#[fg=$TMUX_WINDOW_STATUS_FG,bg=$TMUX_WINDOW_STATUS_BG] #I | #W "

# active window
setw -g window-status-activity-attr "none"
# this isn't picked up either
setw -g window-status-current-format "#[fg=$TMUX_ACTIVE_WINDOW_STATUS_FG,bg=$TMUX_ACTIVE_WINDOW_STATUS_BG] #I | #W "

# panes
set -g pane-active-border-fg $TMUX_ACTIVE_BORDER_FG
set -g pane-border-fg $TMUX_BORDER_FG

# command bar
set -g message-command-fg $TMUX_MESSAGE_COMMAND_FG
set -g message-command-bg $TMUX_MESSAGE_COMMAND_BG
set -g message-fg $TMUX_MESSAGE_FG
set -g message-bg $TMUX_MESSAGE_BG

and this is where I set the colors

# ~/.tmux/themes/gruvbox
TMUX_STATUS_BG="#3c3836"

TMUX_ACTIVE_BORDER_FG="#fabd2f"
TMUX_BORDER_FG="#3c3836"

TMUX_MESSAGE_COMMAND_FG="#a89984"
TMUX_MESSAGE_COMMAND_BG="#3c3836"

TMUX_MESSAGE_FG="#a89984"
TMUX_MESSAGE_BG="#3c3836"

# these aren't picked up, the above vars are
TMUX_WINDOW_STATUS_FG="#a89984"
TMUX_WINDOW_STATUS_BG="#3c3836"

TMUX_ACTIVE_WINDOW_STATUS_FG="#282828"
TMUX_ACTIVE_WINDOW_STATUS_BG="#fabd2f"

It's mostly working, except for the window status variables, which tmux doesn't apply. Do they need a different syntax? If so, which?

  • Are there additional steps to reproduce? In my tests (I tried tmux 1.8 and 2.1, starting a fresh session after each edit), I see .../.tmux.conf:7: bad colour: for every set line using one of these variables -- but no error for the setw lines, oddly. – JigglyNaga Feb 24 '17 at 15:54
  • I think that the problem is that tmux doesn't allow for variables in the window config. So I'm now running a script there with #(~/script.sh) which then echos the config and resolves the variables. Which does work. – user217806 Feb 24 '17 at 16:47
  • I think with tmux the command is: source-file not source – the_velour_fog Feb 26 '17 at 10:54
0

So the window-status setting doesn't allow for the interpolation of variables. But, you can use a script to echo the window config. In that script variables can be used. So in your .tmux.conf you could do something like:

setw -g window-status-current-format "#(~/.tmux/window.sh current)"
setw -g window-status-format "#(~/.tmux/window.sh)"

And in window.sh (or any other script):

#!/bin/bash

if [[ $1 == "current" ]]; then
  echo "#[fg=${TMUX_CURRENT_WINDOW_FG},bg=${TMUX_CURRENT_WINDOW_BG}] #I | #W "
else
  echo "#[fg=${TMUX_WINDOW_FG},bg=${TMUX_WINDOW_BG}] #I | #W "
fi

That does work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy