I have configured my Gnome terminal on Linux Mint 18.3 to always start tmux
by default by adding a couple of lines to my ~/.bashrc
. This works extremely well, except that I also run another script through by adding it to my ~/.bashrc
(one of those fancy custom welcome messages that show up when I open my terminal). As intended, this script is executed every time I open my terminal since it is defined below the execution of tmux
in .bashrc
.
The issue is that every time I subdivide a pane in tmux
, or every time I create a new tab, this same script is executed again. Ideally, I would like to have it executed only when the Gnome terminal first opens (e.g. every time I would press Ctrl+Alt+T
to open the terminal), but not when creating subsequent tabs and panes in an already opened terminal. What would be the best approach to accomplish this, since ~/.bashrc
is executed at every new tab and pane?
I have come across a similar question here but that user wants their script executed only at the system startup. Also, their solution of creating a temporary file as a flag seems very hackish to me. Is there a better way of accomplishing what I want?
Edit: I am executing Tmux by adding the following lines to my .bashrc
file:
# If not running interactively, do not do anything
[[ $- != *i* ]] && return
# Otherwise start tmux
[[ -z "$TMUX" ]] && exec tmux
Unfortunately, replacing the last one with
if [[ -z "$TMUX" ]]; then
exec tmux
my_script
fi
Does not work. In fact, even the test case below does not work; tmux is executed, but neither echo "A"
nor echo "B"
are:
if [[ -z "$TMUX" ]]; then
echo "A"
exec tmux
echo "B"
fi
bashrc
for that), though I have no idea how to do that in Gnome terminal, as I don't use Gnome terminal..bashrc
solution doesn't work. The main question for me is how to execute a script inside tmux immediately afterexec tmux
is summoned. (I made some edits in my question above)exec
replaces the current process with the called process, so afterexec
, nothing in the script gets executed. Also, even if you dropexec
, nothing of that will get executed "inside"tmux
.[[ -z "$TMUX" ]] && exec tmux
is execute inside tmux though, e.g.[[ -z "$TMUX" ]] && exec tmux; echo "inside tmux"
. But after the first line the$TMUX
variable is set and so I can't use that as a conditional for theecho
in this example (or script in my original case)