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
Deprecate restoring shell history #308
Conversation
"restoring shell history" feature is very invasive and dirty. I propose removing it in the future without the replacement. I worry it spoils the first experience of using this plugin for users that accidentally turn it on and don't know how to turn it off, see #288 Also, it hurts me to reject PRs that improve the feature. Thoughts?
@bruno- I'm curious if you have any suggestions on how to replicate this behavior. It's pretty must-have for my use case. |
I'm not sure. Maybe try something with the hooks feature: tmux-resurrect/scripts/restore.sh Line 373 in ca6468e
I'd be open to adding another hook if it helped you. |
Adding this to my HISTS_DIR=$HOME/.bash_history.d
mkdir -p "${HISTS_DIR}"
if [ -n "${TMUX_PANE}" ]; then
PANE=$(echo $TMUX_PANE | sed 's/%//g')
export HISTFILE="${HISTS_DIR}/bash_history_tmux_${PANE}"
else
export HISTFILE="${HISTS_DIR}/bash_history_no_tmux"
fi |
I'm not sure if But I'm sure you can work around that by using something like this:
Of course, you'll have to get each id "component" separately via some If you get it working consider creating a short instruction in |
$TMUX_PANE has been pretty consistent, but I do think I saw it fail at least once. Here's a second attempt: pane_id_prefix="resurrect_"
# Create history directory if it doesn't exist
HISTS_DIR=$HOME/.bash_history.d
mkdir -p "${HISTS_DIR}"
if [ -n "${TMUX_PANE}" ]; then
# Check if we've already set this pane title
pane_id=$(tmux display-message -p '#{pane_title}')
if [[ $pane_id != "$pane_id_prefix"* ]]; then
# if not, set it to a random ID
random_id=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)
printf "\033]2;$pane_id_prefix$random_id\033\\"
pane_id=$(tmux display-message -p '#{pane_title}')
fi
# use the pane's random ID for the HISTFILE
export HISTFILE="${HISTS_DIR}/bash_history_tmux_${pane_id}"
else
export HISTFILE="${HISTS_DIR}/bash_history_no_tmux"
fi To sum up - if the The downside is that you can't customize pane titles, unless you use the same prefix as above (and even then renaming will wipe out your history). There's also the narrow chance of a collision. If you think this is a decent solution I'm happy to submit a PR to |
Can't two panes (in different windows or in different sessions) have the same title? What would be the downside of using |
The issue with I thought about trying to listen for changes to And yes - this solution would force each pane to have a unique title by using a random identifier. |
If you want to do it I'm ok with submitting a PR to I propose clearly mentioning the downsides of this approach and maybe even ask for help? I wouldn't be surprised if someone comes up with a better approach. |
Thanks for this trick, seems like a fairly neat solution. I for one never use pane titles so the loss of them isn't a big deal. I chose to modify the name generator to use the current epoch timestamp plus 1 random character, for cases where multiple panes get created within a second. This has the nice benefit to me of being clear which panes are older than others. Not sure I need that but it seemed convenient to throw it in while at it. So my Edit: in fact, to get rid of the overhead of calling urandom entirely, we can just append milliseconds to the unix timestamp, so that leaves |
Would it help to keep a separate history for each tmux session, and then add it to the overall (e.g.) |
When you create a session and it loads your bashrc/zshrc, for some reason, the pane_id is set to your hostname. I made this shortcut to source it again when creating a new session. If you know of a more ellegant way to deal with this, please tell me. function tms(){
tmux new-session -d -s $1 'source $HOME/.zshrc';
tmux split-window; # split the detached tmux session
tmux send 'source $HOME/.zshrc' ENTER;
tmux send 'clear' ENTER;
tmux a;
}
|
"restoring shell history" feature is very invasive and dirty. I propose
removing it in the future without the replacement.
I worry it spoils the first experience of using this plugin for users
that accidentally turn it on and don't know how to turn it off, see
#288
Also, it hurts me to reject PRs that improve the feature.
Thoughts?