3

How do I change the background color of the tmux bar to a different color depending on if the client is in copy-mode (or not)?

The goal is to make it extremely clear when the tmux client is in copy-mode.

How to detect copy-mode in a format string

I found #{?#{!=:#{selection_present},},COPY-MODE,NORMAL-MODE} works.

What I tried

Set status-left or status-right

This only changes the style of one part of the bar. Example:

set -g status-left '#{?#{!=:#{selection_present},},#[bg=yellow],#[bg=green]}#{=10:session_name}@#{=10:host_short}

This'll show session@hostname in the bottom left, and it will change background, but does not change the color of the entire status bar.

Set status-style with a format string

set -F -g status-style 'bg=#{?#{!=:#{selection_present},},yellow,green},fg=black

This appears to evaluate the format strings only once. Note: If I remove the -F bg does not change.

1 Answer 1

7

You can use a hook, something like:

set-hook -g pane-mode-changed 'if -F "#{m/r:(copy|view)-mode,#{pane_mode}}" "set status-style bg=red" "set -u status-style"'

If your tmux is too old for m/r you can use something like #{||:#{==:#{pane_mode},copy-mode},#{==:#{pane_mode},view-mode}} instead.

Alternatively you could modify status-format[0] but that would be kind of fiddly because status-style is the implicit default.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .