Save tmux daily history

82 views Asked by At

I'll often run things for days inside tmux session, and I like to save my bash history daily (I use logrotate). I do not exit tmux session unless necessary. Could I somehow save my tmux history for that day without exiting the session, on a daily basis, maybe force tmux to write to .bash_history without exiting the session?

I tried :save-buffer /home/me/tmux-hist.txt but that only seems to save last command?

1

There are 1 answers

0
Spiro On

Not sure if this question was for this forum, but I managed to solve it, so here is the solution:

This is not a tmux issue, but rather shell/bash "issue". Adding this to .bashrc:

## Issues with tmux history
# avoid duplicates..
export HISTCONTROL=ignoredups:erasedups
# append history entries:
shopt -s histappend
# After each command, save and reload history:
export PROMPT_COMMAND="history -a; history -n; $PROMPT_COMMAND"

This way commands run in tmux window/pane are added in the history immediately. If you run "echo 1" in pane 1 and then "echo 2" in pane 2 you will see "echo 1" in pane 2 history as well. Daily history is then saved via logrotate.