tmux 如何自定义背景颜色 | How does the tmux color palette work?

╰+哭是因爲堅強的太久メ 2022-10-17 10:58 292阅读 0赞

坑1:256 color support for vim background in tmux

解决终端颜色配置与 tmux 颜色配置不匹配问题。

https://superuser.com/questions/399296/256-color-support-for-vim-background-in-tmux

原因

From the look of your .bashrc and .profile, the shells inside tmux are overriding the ‘default-terminal’ setting in your tmux conf. Something like this:

  • tmux creates new shell with TERM=screen-256color
  • .bashrc/.profile run, set TERM=xterm-256color
  • vim runs, tries to use incorrect TERM for tmux

you can check this by running

  1. echo $TERM

in a fresh tmux shell.

Tmux is relatively picky about having a terminal set correctly. If you can, set the term value in gnome-terminal’s configuration, not in your .bashrc. Failing that, surround those settings with a check for “screen” or “screen-256color” TERM, and don’t reset them in that case.

Tmux REALLY wants the terminal set to screen or screen-256color

解决方法

This is what worked for me in #Ubuntu and #Mac:

  1. # File: ~/.bashrc (Ubuntu), ~/.bash_profile (Mac)
  2. # for VIM and TMUC
  3. if [ "$TERM" = "xterm" ]; then
  4. export TERM=xterm-256color
  5. fi
  6. alias tmux='tmux -2' # for 256color
  7. alias tmux='tmux -u' # to get rid of unicode rendering problem

Reload settings:

$ source ~/.bashrc # Ubuntu

$ source ~/.bash_profile # Mac

Set up .bashrc for Mac (as it is used by tmux)

  1. # File: ~/.bashrc (Mac)
  2. source ~/.bash_profile

Set up “default-terminal” option in ~/.tmux.conf.

  1. # File: ~/.tmux.conf
  2. set -g default-terminal "screen-256color" # Mac and Ubuntu

坑 2:Change background color of active or inactive pane in Tmux

详解 .tmux.conf 配置文件设置背景颜色的方法。其中,fg 是字体颜色,bg 是背景颜色。

https://newbedev.com/change-background-color-of-active-or-inactive-pane-in-tmux

It seems that tmux-2.1 (released 18 October 2015) now allows the colours of individual panes to be specified. From the changelog:

  1. * 'select-pane' now understands '-P' to set window/pane background colours.

e.g. [from the manual] to change pane 1’s foreground (text) to blue and background to red use:

  1. select-pane -t:.1 -P 'fg=blue,bg=red'

To mimic iTerm colour scheme:

To answer the original question, I use the following lines in my ~/.tmux.conf for setting the background/foreground colours to mimic the behaviour in iTerm:

  1. #set inactive/active window styles
  2. set -g window-style 'fg=colour247,bg=colour236'
  3. set -g window-active-style 'fg=colour250,bg=black'
  4. # set the pane border colors
  5. set -g pane-border-style 'fg=colour235,bg=colour238'
  6. set -g pane-active-border-style 'fg=colour51,bg=colour236'

坑 3:Reloading tmux config

写完配置文件后,需要手动 source 使其生效。

https://blog.sanctum.geek.nz/reloading-tmux-config/,Posted on 2012-03-19

If you have made changes to your tmux configuration file in the ~/.tmux.conf file, it shouldn’t be necessary to start the server up again from scratch with kill-server. Instead, you can prompt the current tmux session to reload the configuration with the source-file command.

This can be done either from within tmux, by pressing Ctrl+B and then : to bring up a command prompt, and typing:

  1. :source-file ~/.tmux.conf

Or simply from a shell:

  1. $ tmux source-file ~/.tmux.conf

This should apply your changes to the running tmux server without affecting the sessions or windows within them.

This entry was posted in Tmux and tagged configuration, reload, source, source-file, tmux.conf by Tom Ryder. Bookmark the permalink.


附:tmux 配置中的 colour0~255 颜色表

You can create it with for i in {0..255}; do printf "\x1b[38;5;${i}mcolor%-5i\x1b[0m" $i ; if ! (( ($i + 1 ) % 8 )); then echo ; fi ; done
在这里插入图片描述

配置文件:
在这里插入图片描述

效果:

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,292人围观)

还没有评论,来说两句吧...

相关阅读

    相关 tmux

    什么是Tmux 当你在公司使用SSH连接到公司的机器上,使用Iterm2打开很多窗体。当你回家后,准备工作时,还需要再那打那么多窗体。如果你感觉到烦的话,请使用它。

    相关 tmux使用

    tmux基本使用 tmux是一个优秀的终端复用软件,即使非正常掉线,也能保证当前的任务运行,这一点对于远程SSH访问特别有用,网络不好的情况下仍然能保证工作现场不丢失!

    相关 ubuntu tmux

    tmux是什么 tmux(terminal multiplexer)是Linux上的终端复用神器,可从一个屏幕上管理多个终端(准确说是伪终端)。使用该工具,用户可以连接或