Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash history restore #318

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

javiplx
Copy link

@javiplx javiplx commented Nov 29, 2019

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.

@tessus
Copy link
Contributor

tessus commented Dec 6, 2019

@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.

@javiplx
Copy link
Author

javiplx commented Dec 7, 2019

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

@Magnusgaertner
Copy link

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants