Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing of hostname field color based on hostname itself #322

Open
Halfwalker opened this issue Feb 29, 2020 · 4 comments
Open

Allow changing of hostname field color based on hostname itself #322

Halfwalker opened this issue Feb 29, 2020 · 4 comments

Comments

@Halfwalker
Copy link

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_staging_1, match on "staging" and change hostname color to YELLOW. If it's machine_prod_1 then change to BLUE.

@gpakosz
Copy link
Owner

gpakosz commented Mar 4, 2020

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

@indirect
Copy link

indirect commented Aug 3, 2020

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?

@gpakosz
Copy link
Owner

gpakosz commented Jan 22, 2023

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

@indirect
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants