tmux-resurrect icon indicating copy to clipboard operation
tmux-resurrect copied to clipboard

bash history restore

Open javiplx opened this issue 4 years ago • 3 comments

The changes basically replace the use of pane_index by pane_id. This guarantees that the environment variable TMUX_PANE is consistent across restores, and allows to use it as index to get separate history files for different panes. I have this on my .bashrc, to set the right history filename in tmux and to update it on every command

HISTFILE=${HISTFILE}${TMUX_PANE:+.${TMUX_PANE#%}}
[ x$TMUX_PANE != x ] && PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND$'\n'}history -a"

Main problem was restoring directory & content of the very first pane (`%0'), but I've included an alias for that.

javiplx avatar Nov 29 '19 20:11 javiplx

@javiplx interesting. I'm using the following with git master and it works splendidly:

[[ "$TMUX" ]] && TSWP=`tmux display -pt "${TMUX_PANE:?}" '#{session_name}:#{window_index}.#{pane_index}'` && HISTFILE=$HOME/.bash_history.d/bash_history-$TSWP
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

My histories are always restored properly. Just wondering why this change would make this any better.

tessus avatar Dec 06 '19 11:12 tessus

My histories are always restored properly. Just wondering why this change would make this any better.

Maybe if you reorder panes, or delete some but the last one, or many other changes in the layout, you'll notice that your history is not so well restored.
The TMUX_PANE/pane_id instead is a unique identifier that is kept along the tmux session. Most of my changes target to keep them also across resurrections

javiplx avatar Dec 07 '19 12:12 javiplx

@javiplx interesting. I'm using the following with git master and it works splendidly:

[[ "$TMUX" ]] && TSWP=`tmux display -pt "${TMUX_PANE:?}" '#{session_name}:#{window_index}.#{pane_index}'` && HISTFILE=$HOME/.bash_history.d/bash_history-$TSWP
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"

My histories are always restored properly. Just wondering why this change would make this any better.

Thanks alot, but make sure that ~/.bash_history.d/ exists as a folder :)

Magnusgaertner avatar Aug 03 '20 17:08 Magnusgaertner