Remove deprecated "restoring shell history"

This commit is contained in:
Bruno Sutic 2022-04-10 08:58:27 +02:00
parent e87d7d592c
commit 6050d2d8d8
No known key found for this signature in database
GPG Key ID: CAFA7B1B2914ED81
8 changed files with 2 additions and 123 deletions

View File

@ -1,6 +1,7 @@
# Changelog # Changelog
### master ### master
- Remove deprecated "restoring shell history" feature.
### v4.0.0, 2022-04-10 ### v4.0.0, 2022-04-10
- Proper handling of `automatic-rename` window option. - Proper handling of `automatic-rename` window option.

View File

@ -104,10 +104,6 @@ You should now be able to use the plugin.
is nice if you're a vim/neovim user. is nice if you're a vim/neovim user.
- [Restoring pane contents](docs/restoring_pane_contents.md) feature. - [Restoring pane contents](docs/restoring_pane_contents.md) feature.
**Experimental features (also optional)**
- [restoring shell history](docs/restoring_shell_history.md)
### Other goodies ### Other goodies
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin for - [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin for

View File

@ -20,15 +20,9 @@ Currently the following hooks are supported:
Called before any tmux state is altered. Called before any tmux state is altered.
- `@resurrect-hook-pre-restore-history` - deprecated
Called after panes and layout have been restores, but before bash history is
restored (if it is enabled) -- the hook is always called even if history
saving is disabled.
- `@resurrect-hook-pre-restore-pane-processes` - `@resurrect-hook-pre-restore-pane-processes`
Called after history is restored, but before running processes are restored. Called before running processes are restored.
### Examples ### Examples

View File

@ -1,23 +0,0 @@
# Restoring shell history (deprecated, do not use)
This feature is deprecated because it's very invasive. It will be removed in
the future with no replacement. To see problems it causes check
[this issue](https://github.com/tmux-plugins/tmux-resurrect/issues/288).
**Supported shells**: `bash` and `zsh`.
Enable feature with this option in `.tmux.conf`:
set -g @resurrect-save-shell-history 'on'
**Note**: the older `@resurrect-save-bash-history` is now an alias to
`@resurrect-save-shell-history`.
Shell `history` for individual panes will now be saved and restored. Due to
technical limitations, this only works for panes which have no program running
in foreground when saving. `tmux-resurrect` will send history write command to
each such pane.
To prevent these commands from being added to `bash` history
themselves, add `HISTCONTROL=ignoreboth` to your `.bashrc`
(this is set by default in Ubuntu).

View File

@ -64,13 +64,6 @@ files_differ() {
! cmp -s "$1" "$2" ! cmp -s "$1" "$2"
} }
save_shell_history_option_on() {
local option_shell="$(get_tmux_option "$shell_history_option" "off")"
local option_bash="$(get_tmux_option "$bash_history_option" "off")"
[ "$option_shell" == "on" ] || [ "$option_bash" == "on" ]
}
get_grouped_sessions() { get_grouped_sessions() {
local grouped_sessions_dump="$1" local grouped_sessions_dump="$1"
export GROUPED_SESSIONS="${d}$(echo "$grouped_sessions_dump" | cut -f2 -d"$d" | tr "\\n" "$d")" export GROUPED_SESSIONS="${d}$(echo "$grouped_sessions_dump" | cut -f2 -d"$d" | tr "\\n" "$d")"
@ -143,12 +136,6 @@ pane_contents_archive_file() {
echo "$(resurrect_dir)/pane_contents.tar.gz" echo "$(resurrect_dir)/pane_contents.tar.gz"
} }
resurrect_history_file() {
local pane_id="$1"
local shell_name="$2"
echo "$(resurrect_dir)/${shell_name}_history-${pane_id}"
}
execute_hook() { execute_hook() {
local kind="$1" local kind="$1"
shift shift

View File

@ -303,25 +303,6 @@ restore_window_properties() {
done done
} }
restore_shell_history() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ { print $2, $3, $6, $9; }' $(last_resurrect_file) |
while IFS=$d read session_name window_number pane_index pane_command; do
if ! is_pane_registered_as_existing "$session_name" "$window_number" "$pane_index"; then
local pane_id="$session_name:$window_number.$pane_index"
local history_file="$(resurrect_history_file "$pane_id" "$pane_command")"
if [ "$pane_command" = "bash" ]; then
local read_command="history -r '$history_file'"
tmux send-keys -t "$pane_id" "$read_command" C-m
elif [ "$pane_command" = "zsh" ]; then
local accept_line="$(expr "$(zsh -i -c bindkey | grep -m1 '\saccept-line$')" : '^"\(.*\)".*')"
local read_command="fc -R '$history_file'; clear"
tmux send-keys -t "$pane_id" "$read_command" "$accept_line"
fi
fi
done
}
restore_all_pane_processes() { restore_all_pane_processes() {
if restore_pane_processes_enabled; then if restore_pane_processes_enabled; then
local pane_full_command local pane_full_command
@ -389,10 +370,6 @@ main() {
restore_all_panes restore_all_panes
handle_session_0 handle_session_0
restore_window_properties >/dev/null 2>&1 restore_window_properties >/dev/null 2>&1
execute_hook "pre-restore-history"
if save_shell_history_option_on; then
restore_shell_history
fi
execute_hook "pre-restore-pane-processes" execute_hook "pre-restore-pane-processes"
restore_all_pane_processes restore_all_pane_processes
# below functions restore exact cursor positions # below functions restore exact cursor positions

View File

@ -144,46 +144,6 @@ capture_pane_contents() {
fi fi
} }
save_shell_history() {
if [ "$pane_command" = "bash" ]; then
local history_w='history -w'
local history_r='history -r'
local accept_line='C-m'
local end_of_line='C-e'
local backward_kill_line='C-u'
elif [ "$pane_command" = "zsh" ]; then
# fc -W does not work with -L
# fc -l format is different from what's written by fc -W
# fc -R either reads the format produced by fc -W or considers
# the entire line to be a command. That's why we need -n.
# fc -l only list the last 16 items by default, I think 64 is more reasonable.
local history_w='fc -lLn -64 >'
local history_r='fc -R'
local zsh_bindkey="$(zsh -i -c bindkey)"
local accept_line="$(expr "$(echo "$zsh_bindkey" | grep -m1 '\saccept-line$')" : '^"\(.*\)".*')"
local end_of_line="$(expr "$(echo "$zsh_bindkey" | grep -m1 '\send-of-line$')" : '^"\(.*\)".*')"
local backward_kill_line="$(expr "$(echo "$zsh_bindkey" | grep -m1 '\sbackward-kill-line$')" : '^"\(.*\)".*')"
else
return
fi
local pane_id="$1"
local pane_command="$2"
local full_command="$3"
if [ "$full_command" = ":" ]; then
# leading space prevents the command from being saved to history
# (assuming default HISTCONTROL settings)
local write_command=" $history_w '$(resurrect_history_file "$pane_id" "$pane_command")'"
local read_command=" $history_r '$(resurrect_history_file "$pane_id" "$pane_command")'"
# C-e C-u is a Bash shortcut sequence to clear whole line. It is necessary to
# delete any pending input so it does not interfere with our history command.
tmux send-keys -t "$pane_id" "$end_of_line" "$backward_kill_line" "$write_command" "$accept_line"
# Immediately restore after saving
tmux send-keys -t "$pane_id" "$end_of_line" "$backward_kill_line" "$read_command" "$accept_line"
fi
}
get_active_window_index() { get_active_window_index() {
local session_name="$1" local session_name="$1"
tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" | tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" |
@ -266,13 +226,6 @@ dump_pane_contents() {
done done
} }
dump_shell_history() {
dump_panes |
while IFS=$d read line_type session_name window_number window_active window_flags pane_index dir pane_active pane_command full_command; do
save_shell_history "$session_name:$window_number.$pane_index" "$pane_command" "$full_command"
done
}
remove_old_backups() { remove_old_backups() {
# remove resurrect files older than 30 days (default), but keep at least 5 copies of backup. # remove resurrect files older than 30 days (default), but keep at least 5 copies of backup.
local delete_after="$(get_tmux_option "$delete_backup_after_option" "$default_delete_backup_after")" local delete_after="$(get_tmux_option "$delete_backup_after_option" "$default_delete_backup_after")"
@ -302,9 +255,6 @@ save_all() {
pane_contents_create_archive pane_contents_create_archive
rm "$(pane_contents_dir "save")"/* rm "$(pane_contents_dir "save")"/*
fi fi
if save_shell_history_option_on; then
dump_shell_history
fi
remove_old_backups remove_old_backups
execute_hook "post-save-all" execute_hook "post-save-all"
} }

View File

@ -38,9 +38,6 @@ pane_contents_option="@resurrect-capture-pane-contents"
pane_contents_area_option="@resurrect-pane-contents-area" pane_contents_area_option="@resurrect-pane-contents-area"
default_pane_contents_area="full" default_pane_contents_area="full"
bash_history_option="@resurrect-save-bash-history" # deprecated
shell_history_option="@resurrect-save-shell-history" # deprecated
# set to 'on' to ensure panes are never ever overwritten # set to 'on' to ensure panes are never ever overwritten
overwrite_option="@resurrect-never-overwrite" overwrite_option="@resurrect-never-overwrite"