I like to keep my bash_profile in a git repository and clone it to whatever machines I have shell access to. Since I'm in tmux most of the time I have a user@host string in the status line, rather than its traditional spot in the shell prompt.
Not all sites I use have tmux installed, though, or I may not always be using it. I'd like to detect when I'm not in a tmux session and adjust my prompt accordingly. So far my half-baked solution in .bash_profile looks something like this:
_display_host_unless_in_tmux_session() {
# ???
}
export PROMPT_COMMAND='PS1=$(_display_host_unless_in_tmux_session)${REST_OF_PROMPT}'
(Checking every time probably isn't the best approach, so I'm open to suggestions for a better way of doing this. Bash scripting is not my forte.)
TMUX_PANEas well. I only noticed because your recipe didn't work. Later I found out that I had unduly used (and subsequentlyunset) a variable in a shell script I am sourcing through my.profile. – 0xC0000022L Jun 02 '14 at 23:23[ "$TERM" = "screen" ]may not work. In my case, my screen was reporting asscreen-256color. – StevieD Apr 07 '19 at 13:59TERMvar is a reflection of what's in mytmuxconfig. In my caseset -g default-terminal "tmux-256color", soTERM=tmux-256coloris what is set in my env. – oalders Nov 11 '21 at 20:52tmuxandtmux-256colorhas been added to terminfo. Nowadays$TERMin tmux should be one of these two, notscreen, notscreen-256color. Still one can use something else with tmux commandset -g default-terminal …. – Kamil Maciorowski Jul 12 '23 at 05:20