Reputation: 1132
Preface: My current tmux configuration has multiple panes in multiple windows in multiple sessions.
The problem that keeps arising is that when I work in one window, all my history is good and separate between that window's panes, and when I swap windows/sessions, that history is initially separate too, but only until I enter one command in a different window/session.
Once that happens, all the history for all panes gets merged together and it's sometimes impossible to find a certain pane's actual last command, depending on how long it had been since I was on the pane.
Is there any way to avoid this and have each pane have its own shell history?
Upvotes: 18
Views: 4644
Reputation: 312400
If you're using the bash
shell, your command history is written to a file defined by the HISTFILE
variable, which defaults to ~/.bash_history
. Inside a tmux
pane, you have access to the variable $TMUX_PANE
which looks something like this:
$ echo $TMUX_PANE
%3
You could use this to create a per-pane history by adding something like this to your ~/.bashrc
file:
if [[ $TMUX_PANE ]]; then
HISTFILE=$HOME/.bash_history_tmux_${TMUX_PANE:1}
fi
This will store the history for pane 2, for example, in ~/.bash_history_tmux_2
.
The downside to this idea is that you're going to end up with a bunch of .bash_history_tmux_*
files in your home directory.
Upvotes: 16