25
votes

I did some updating on my Mac and seem to have broken some of my settings. I have the following set in my .bash_profile

export PS1="\W $"

This is working in my normal bash session to show just the current directory instead of the whole path. However, when I switch into tmux, it again displays the whole path. Other changes to the PS1 in the bash profile such as color or other characters work fine and are reflected in tmux. I have emptied out my .tmux.conf to see if that was causing conflict but there was no change to this behavior.

I did create a new user on the system and tried the same PS1 and it worked perfectly in both a normal session and tmux.

I am mostly confused because I know I had it working and can't figure out what would have changed in the update. What files besides .bash_profile and .tmux.conf could be at play here? Is there a way to tell where tmux is pulling it's settings from?

Additional info: This behavior is the same in both iTerm2 and Terminal Tmux version 1.8 Mac OSX 10.9.1

9
tmux may be creating non-login shells, in which case .bashrc would be sourced instead. - chepner
I don't think that is the case as the other aliases in my .bash_profile are carrying over into tmux and any other changes I make to the PS1 reflect properly in tmux however the \W variable just doesn't seem to want to behave normally. - Paige
once you're in tmux, what is $PS1 set to? - graywh

9 Answers

-5
votes

Add the following to your .tmux.conf:

new -n WindowName bash --login

You can replace WindowName with whatever you want the first window to be named. When bash is invoked this way, it sources to your .bash_profile, .bash_rc, .profile, etc. which is where you change your $PS1.

35
votes

This one works for me: In tmux/terminal:

tmux set-option -g default-command bash

Or simply put into ~/.tmux.conf:

set-option -g default-command bash
12
votes

Add the following in your ~/.tmux.conf

set -g default-terminal "tmux-256color" 

From the beloved ArchWiki tmux

7
votes

I have the similar problem. I get the correct result if I always start tmux with the bash command applied, like so:

tmux new bash

So, to simplify this, I just created an alias in my ~/.bash_aliases file, which I use all the time:

alias tn='tmux new bash'

This does only work for the first window though. When creating new windows, you have to start bash again, by executing bash in the terminal.

4
votes

I had the same problem and after some research I have added the following command to my ~/.tmux.conf:

set-option -g default-command "reattach-to-user-namespace -l /opt/local/bin/bash --login"

I am using OSX 10.9.5 with iTerm2 Build 2.0.0.20141103, bash 4.3.30(1)-release, tmux 1.9a. Bash and tmux are from macports.

4
votes

Add the following line to ~/.tmux.conf:

set -g default-terminal "screen-256color"

Don't forget to save ~/.tmux.conf and restart tmux in order for the changes to take effect.

1
votes

I know I'm far late to the party. But here's what worked for me.

I just added -256color to TERM.

  1. Open/Run tmux.
  2. Run the following command: echo $TERM. We are gonna use the output of this. I got screen. Use your own in the next step.
  3. Edit your tmux conf file: vim ~/.tmux.conf and add this line: set -g default-terminal screen-256color.
  4. Exit tmux.
  5. Open/Run tmux again.

Using tmux-256color didn't work for me. I'm using Ubuntu 18.04, bash 4.4.20, tmux 2.6.

0
votes

When using tmux with byobu, you can try the byobu-prompt command. It'will ask you whether you want a bash color prompt. After answering Yes, the prompt will change to the usual user@host.

0
votes

Better to detect which terminals are known to the system's terminfo database via the infocmp command. I've got the following in my ~/.tmux.conf:

# Last match wins
if-shell "infocmp xterm-256color" "set-option -g default-terminal xterm-256color"
if-shell "infocmp screen-256color" "set-option -g default-terminal screen-256color"
if-shell "infocmp tmux" "set-option -g default-terminal tmux"

If the infocmp shell-command succeeds, then the following set-option tmux command is executed.