Open Halfwalker opened 4 years ago
Related to #321
You can combine #{?}
, #{==:}
, #{m:}
and #{m/r:}
:
tmux_conf_theme_status_right='#{?#{==:#{hostname},#h},#[fg=green],}#{?#{m:*staging*,#{hostname}},#[fg=yellow],}#{?#{m/r:^.*prod.*$,#{hostname}},#[fg=blue],}#{hostname}#[inherit]'
I'm not sure how I want to generalize this. This doesn't compose well with segment colors
I think it composes reasonably well with segment colors if you set the segment colors in a conditional:
%if "#{m:*staging*,#{hostname}}"
tmux_conf_theme_status_left_bg='#00ff00,#000000'
%else
tmux_conf_theme_status_left_bg='#ff0000,#000000'
%endif
In that approach, the only duplication is the segment colors that don't change. Seems... okay?
Hey @indirect 👋
Sorry for the late follow up. Just wanted to mention that %if
is evaluated at configuration parsing time. As such, what you're suggesting doesn't work if you want the color to change when e.g. sshing into some host
Thanks for explaining! This worked for me because I have a separate tmux session for each box, and either nest tmux or create a new terminal to host the tmux session on the remote machine. In that case, you'll get different colors on the different machines' long-running tmux sessions.
Set up a table or block of variables to associate hostnames with colors. Even better if it could use a regex to match on hostname patterns. Then change the hostname field color to match.
If I'm on local machine, hostname color is GREEN. If I ssh into _machine_staging1, match on "staging" and change hostname color to YELLOW. If it's _machine_prod1 then change to BLUE.