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_PANE
as 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-256
color. – StevieD Apr 07 '19 at 13:59TERM
var is a reflection of what's in mytmux
config. In my caseset -g default-terminal "tmux-256color"
, soTERM=tmux-256color
is what is set in my env. – oalders Nov 11 '21 at 20:52tmux
andtmux-256color
has been added to terminfo. Nowadays$TERM
in 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