tmux not colorizing PS1 prompt
Solution 1
Your PS1 also gives me black and white output.
However switching back to mine gives me color, so you should be able to figure out the different, I use
$ 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\$
git_branch is a bash function I have which is:
git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
Yours vs. Mine:
This works the same on OSX and Ubuntu
Solution 2
On my machine the solution is to add
set -g default-terminal "xterm-256color"
to ~/.tmux.conf
.
Solution 3
My solution to this problem was setting
force_color_prompt=yes
in my .bashrc
. Now my tmux prompt has color.
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
Admin over 1 year
I recently decided to change my PS1 variable to accommodate some pretty Solarized colors for my terminal viewing pleasure. When not in a tmux session, everything is great! Rainbows, ponies, unicorns and a distinguishable prompt! Cool!
The problem is within tmux, however. I've verified that the value of PS1 is what I expect it to be and the same as it is when tmux isn't running, namely
\[\033]0;\w\007\]\[\[\]\]\u\[\]@\[\[\]\]\h\[\]:\[\]\W\[\]$ \[\]
.All of my aliases, etc. in my .bash_profile are also functioning as expected. tmux is also displaying colors without incident, as
echo -ne "\033[1;33m hi"
behaves as expected as doesgls --color
.The current relevant line in my .bash_profile is
export PS1="\[\033]0;\w\007\]\[\[\]\]\u\[\]@\[\[\]\]\h\[\]:\[\]\W\[\]$ \[\]"
, although originally I was sourcing a script located in a .bash_prompt file to handle some conditionals, etc. I tried reverting to the simpler version.Executing
bash
will cause the prompt to colorize, but must be done in each pane.export PS1=[that long string I've already posted]
will not.My .tmux.conf is as follows:
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}"
Relevant portions of .bash_profile:
export TERM="xterm-256color" if which tmux >/dev/null 2>&1; then test -z "$TMUX" && (tmux attach || tmux new-session) fi
I'm using macOS Sierra, iTerm 2, I've tried both the current homebrew version of bash and the system bash (it's currently using the homebrew), tmux 2.4.
I also placed
touch testing_touch_from_bash_profile
in my .bash_profile while in a tmux session with two panes, killed one pane, opened a pane and verified that the file was in fact created.echo $TERM
returnsxterm-256color
.I've ensured that when exiting tmux to test settings changes that I've exited tmux and that no tmux process is currently running on the system via
ps -ax | grep tmux
.Oddly, sourcing the .bash_prompt script also changes the color so long as I do it within each tmux pane.
I've looked at https://stackoverflow.com/questions/21005966/tmux-prompt-not-following-normal-bash-prompt-ps1-w and tried adding the --login flag after the bash call in the first line of my .tmux.conf. Launching tmux with
tmux new bash
will cause the first pane to colorize, but subsequent panes will not.The $PS1 variable is being honored for seemingly all aspects except colorizing any of the fields.
Anyone have any ideas?
-
Matt Lacey about 5 yearsNot sure why this behaves differently in tmux to outside of it, but this did the trick for me too.
-
evaristegd almost 5 yearsI th ink you should specify this: what you have to do is run the command
tmux
, and then inside a tmux session runsource ~/.bashrc
. You need to do that in each panel. -
intijk over 4 yearsThanks, this work for me also on Ubuntu 18.04 gnome-terminal.
-
ipetrik almost 4 yearsThis seems like the cleanest solution. Thank you.
-
webofmars over 3 years-1 This in fact dosent give him an answer to the question posted but instead show him that there is an error in his example. This should be handled has a comment rather that an "answer" IMHO
-
ciencia over 2 yearsFor me,
xterm-256color
works but disables the home and end keyboard keys.screen-256color
works too without the keyboard problem on Debian.