1

I often find myself in this situation:

  • I start doing something in a terminal.
  • I need more terminal space, so I open tmux.
  • History is gone, even the commands I wanted to run inside tmux.

How can I port over the current bash history into a new tmux session? Ideally something I can add to tmux configuration and otherwise something I can put in an alias like tmuxhist.

1
  • 1
    You could always try switching to zsh, universal history in every terminal.
    – Alex Berry
    Aug 1, 2014 at 10:30

2 Answers 2

2

Put this in your ~/.bashrc:

export PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
shopt -s histappend

This solution is not specific to tmux, it'll also work with GNU screen or tabbed terminals or just opening new xterm windows. Basically, it says "append to history on every command, and make sure bash doesn't empty the history file on exit".

That also means you can open a new pane in tmux and ctrl+p to get the last command executed in the previous pane.

0

history -w; tmux does the trick somewhat.

alias tmuxhist='history -w; tmux' creates an alias for it.

Unfortunately it's not possible to add commands to be executed at startup in tmux configuration.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .