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 does gls --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)

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 returns xterm-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?

  • Try single quotes – Kevin Apr 22 '17 at 5:24
  • 4
    The PS1 setting you posted doesn't have any command to change colors. Post an actual setting that does work outside tmux. Also, you should set PS1 in .bashrc, not in .bash_profile: .bash_profile might not get executed at all, and the settings might be overridden later. – Gilles 'SO- stop being evil' Apr 22 '17 at 21:42

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:

enter image description here

This works the same on OSX and Ubuntu


My solution to this problem was setting


in my .bashrc. Now my tmux prompt has color.

  • Not sure why this behaves differently in tmux to outside of it, but this did the trick for me too. – Matt Lacey Feb 22 '19 at 2:01
  • I th ink you should specify this: what you have to do is run the command tmux , and then inside a tmux session run source ~/.bashrc . You need to do that in each panel. – evaristegd Jul 19 '19 at 5:59
  • Thanks, this work for me also on Ubuntu 18.04 gnome-terminal. – intijk Nov 27 '19 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.