tmux-plugins / tmux-resurrect

Persists tmux environment across system restarts.
MIT License
11.39k stars 423 forks source link

Preserve bash history #48

Closed rburny closed 10 years ago

rburny commented 10 years ago

Please consider saving Bash history for each pane. This can be done relatively simply (on Bash side) by using following commands:

# save history
history -w $HISTORY_FILE
# restore
history -r $HISTORY_FILE

How to send these commands to each pane is a trickier question, but I believe tmux's send-keys functionality can achieve this - at least when no program is running in given pane.

bruno- commented 10 years ago

Hi, thanks for the suggestion, this would be an interesting feature.

Yes, tmux send-keys can do this, but I see a few downsides:

rburny commented 10 years ago

Yes, I understand some people might find such feature intrusive or surprising. It should likely by flag-gated, so whoever enables the flag knows what he's doing.

Restricting save to panes not running any program could work based on #{pane_current_format} value, which is already extracted from tmux. If user really needs to save "running" pane history, he can pause running program himself with Ctrl-z.

As for "dirtying" user state - I did some research and I think impact can be minimized:

As you can see, the only annoyance is visible history write, and the history itself is never clobbered.

The use case for such feature is as follows. I usually have a few panes open: one for editing, one for build/unit testing, others for deployment. If I need to restart machine, the most annoying part is to recall all the commands. Having tmux-resurrect restore windows & working dirs is great, but having history would make it perfect!

bruno- commented 10 years ago

Flag-gating this makes sense. Ok, you got me convinced. If you can make this feature work (and it doesn't majorly screw up other things) submit a pull request and we'll "polish" the feature together and merge it.

Saving the history should probably be hooked at the end of this function. Restoring the history should go before this function.

Don't worry about flag-gating this or making the code nice - we can do that later.

rburny commented 10 years ago

I have pushed an implementation to my repo (see https://github.com/rburny/tmux-resurrect/commit/f69b64e994474fb66fe85612ac50333f1887071f)

This does not have flag-gating, but I think it's pretty complete otherwise. Should I open a pull request?

bruno- commented 10 years ago

Hi, thank you for the work. No need to open a pull request - I'll cherry-pick your commit (you'll still be shown as a committer), test it and do the rest of the work.

bruno- commented 10 years ago

@rburny, all looks good. Can you please check pull request #49 and see if you have any comments? If not, I think that one is ready for merging into master.

bruno- commented 10 years ago

This was implemented in #49

unphased commented 9 years ago

Any chance this is similarly simple to do for zsh?