tmux 不着色 PS1 提示

J. *_*ton 25 osx bash prompt tmux

我最近决定更改我的 PS1 变量以适应一些漂亮的 Solarized 颜色,以获得我的终端观看乐趣。当不在 tmux 会话中时,一切都很棒!彩虹、小马、独角兽和可区分的提示!凉爽的!

然而,问题出在 tmux 中。我已经验证了 PS1 的值是我期望的值,并且与 tmux 未运行时的值相同,即\[\033]0;\w\007\]\[\[\]\]\u\[\]@\[\[\]\]\h\[\]:\[\]\W\[\]$ \[\].

我的 .bash_profile 中的所有别名等也按预期运行。tmux 也无意外地显示颜色,echo -ne "\033[1;33m hi"正如预期的那样gls --color

我的 .bash_profile 中当前的相关行是export PS1="\[\033]0;\w\007\]\[\[\]\]\u\[\]@\[\[\]\]\h\[\]:\[\]\W\[\]$ \[\]",尽管最初我正在采购位于 .bash_prompt 文件中的脚本来处理一些条件等。我尝试恢复到更简单的版本。

执行bash将导致提示着色,但必须在每个窗格中完成。export PS1=[that long string I've already posted]将不会。

我的 .tmux.conf 如下:

set-option -g default-command "reattach-to-user-namespace -l /usr/local/bin/bash"
set -g default-terminal "xterm-256color"
set-window-option -g automatic-rename on
bind '"' split-window -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
bind c new-window -c "#{pane_current_path}"
Run Code Online (Sandbox Code Playgroud)

.bash_profile 的相关部分:

export TERM="xterm-256color"
if which tmux >/dev/null 2>&1; then
    test -z "$TMUX" && (tmux attach || tmux new-session)
fi
Run Code Online (Sandbox Code Playgroud)

我正在使用 macOS Sierra,iTerm 2,我已经尝试了当前自制版本的 bash 和系统 bash(它当前使用的是自制软件),tmux 2.4。

我还在touch testing_touch_from_bash_profile我的 .bash_profile 中放入了我的 .bash_profile ,同时在有两个窗格的 tmux 会话中,杀死了一个窗格,打开了一个窗格并验证该文件实际上是创建的。

echo $TERM返回xterm-256color

我确保在退出 tmux 以测试设置更改时,我已经退出了 tmux 并且当前没有 tmux 进程通过ps -ax | grep tmux.

奇怪的是,只要我在每个 tmux 窗格中执行,获取 .bash_prompt 脚本也会改变颜色。

我查看了/sf/ask/1470417651/并尝试在第一行的 bash 调用后添加 --login 标志我的.tmux.conf。启动 tmux withtmux new bash将导致第一个窗格着色,但后续窗格不会。

除了为任何字段着色之外,$PS1 变量似乎在所有方面都受到尊重。

谁有想法?

Siy*_*Ren 36

在我的机器上,解决方案是添加

set -g default-terminal "xterm-256color"
Run Code Online (Sandbox Code Playgroud)

~/.tmux.conf

  • 对我来说,“xterm-256color”可以工作,但会禁用 home 和 end 键盘键。`screen-256color` 在 Debian 上也可以正常工作,不会出现键盘问题。 (3认同)

Pan*_*nki 21

我对这个问题的解决方案是设置

force_color_prompt=yes

在我的.bashrc. 现在我的 tmux 提示有颜色。

  • 我认为你应该指定:你必须做的是运行命令 `tmux`,然后在 tmux 会话中运行 `source ~/.bashrc`。您需要在每个面板中执行此操作。 (2认同)

Mic*_*ant 2

你的 PS1 还提供黑白输出。

然而切换回我的给了我颜色,所以你应该能够找出不同的,我使用

$ echo $PS1
\[\033[01;31m\]\t \[\033[01;32m\]durrantm \[\033[02;36m\]\h \[\033[01;34m\]`pwd | sed "s#\(/[^/]\{1,\}/[^/]\{1,\}/[^/]\{1,\}/\).*\(/[^/]\{1,\}/[^/]\{1,\}\)/\{0,1\}#\1_\2#g"` \[\033[00;33m\]$(git_branch)\[\033[00m\]\n\$
Run Code Online (Sandbox Code Playgroud)

git_branch 是我的一个 bash 函数,它是:

git_branch () { 
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
Run Code Online (Sandbox Code Playgroud)

你的与我的:

在此输入图像描述

这在 OSX 和 Ubuntu 上的工作原理相同

  • -1 这实际上并没有给他所发布问题的答案,而是向他表明他的示例中有错误。这应该通过评论来处理,而不是“答案”恕我直言 (2认同)