Merge branch 'tmux-plugins:master' into master
commit
bd373b8760
|
@ -1,7 +1,12 @@
|
|||
# Changelog
|
||||
|
||||
### master
|
||||
- Remove deprecated "restoring shell history" feature.
|
||||
|
||||
### v4.0.0, 2022-04-10
|
||||
- Proper handling of `automatic-rename` window option.
|
||||
- save and restore tmux pane title (breaking change: you have to re-save to be
|
||||
able to properly restore!)
|
||||
|
||||
### v3.0.0, 2021-08-30
|
||||
- save and restore tmux pane contents (@laomaiweng)
|
||||
|
|
|
@ -104,10 +104,6 @@ You should now be able to use the plugin.
|
|||
is nice if you're a vim/neovim user.
|
||||
- [Restoring pane contents](docs/restoring_pane_contents.md) feature.
|
||||
|
||||
**Experimental features (also optional)**
|
||||
|
||||
- [restoring shell history](docs/restoring_shell_history.md)
|
||||
|
||||
### Other goodies
|
||||
|
||||
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin for
|
||||
|
|
|
@ -20,15 +20,9 @@ Currently the following hooks are supported:
|
|||
|
||||
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`
|
||||
|
||||
Called after history is restored, but before running processes are restored.
|
||||
Called before running processes are restored.
|
||||
|
||||
### Examples
|
||||
|
||||
|
|
|
@ -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).
|
|
@ -64,13 +64,6 @@ files_differ() {
|
|||
! 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() {
|
||||
local grouped_sessions_dump="$1"
|
||||
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"
|
||||
}
|
||||
|
||||
resurrect_history_file() {
|
||||
local pane_id="$1"
|
||||
local shell_name="$2"
|
||||
echo "$(resurrect_dir)/${shell_name}_history-${pane_id}"
|
||||
}
|
||||
|
||||
execute_hook() {
|
||||
local kind="$1"
|
||||
shift
|
||||
|
|
|
@ -170,12 +170,12 @@ new_pane() {
|
|||
tmux split-window -t "${session_name}:${window_number}" -c "$dir"
|
||||
fi
|
||||
# minimize window so more panes can fit
|
||||
tmux resize-pane -t "${session_name}:${window_number}" -U "999"
|
||||
tmux resize-pane -t "${session_name}:${window_number}" -U "999"
|
||||
}
|
||||
|
||||
restore_pane() {
|
||||
local pane="$1"
|
||||
while IFS=$d read line_type session_name window_number window_active window_flags pane_index dir pane_active pane_command pane_full_command; do
|
||||
while IFS=$d read line_type session_name window_number window_active window_flags pane_index pane_title dir pane_active pane_command pane_full_command; do
|
||||
dir="$(remove_first_char "$dir")"
|
||||
pane_full_command="$(remove_first_char "$pane_full_command")"
|
||||
if [ "$session_name" == "0" ]; then
|
||||
|
@ -200,6 +200,8 @@ restore_pane() {
|
|||
else
|
||||
new_session "$session_name" "$window_number" "$dir" "$pane_index"
|
||||
fi
|
||||
# set pane title
|
||||
tmux select-pane -t "$session_name:$window_number.$pane_index" -T "$pane_title"
|
||||
done < <(echo "$pane")
|
||||
}
|
||||
|
||||
|
@ -301,29 +303,10 @@ restore_window_properties() {
|
|||
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() {
|
||||
if restore_pane_processes_enabled; then
|
||||
local pane_full_command
|
||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $10 !~ "^:$" { print $2, $3, $6, $7, $10; }' $(last_resurrect_file) |
|
||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $6, $8, $11; }' $(last_resurrect_file) |
|
||||
while IFS=$d read -r session_name window_number pane_index dir pane_full_command; do
|
||||
dir="$(remove_first_char "$dir")"
|
||||
pane_full_command="$(remove_first_char "$pane_full_command")"
|
||||
|
@ -333,7 +316,7 @@ restore_all_pane_processes() {
|
|||
}
|
||||
|
||||
restore_active_pane_for_each_window() {
|
||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $8 == 1 { print $2, $3, $6; }' $(last_resurrect_file) |
|
||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $6; }' $(last_resurrect_file) |
|
||||
while IFS=$d read session_name window_number active_pane; do
|
||||
tmux switch-client -t "${session_name}:${window_number}"
|
||||
tmux select-pane -t "$active_pane"
|
||||
|
@ -341,7 +324,7 @@ restore_active_pane_for_each_window() {
|
|||
}
|
||||
|
||||
restore_zoomed_windows() {
|
||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $5 ~ /Z/ && $8 == 1 { print $2, $3; }' $(last_resurrect_file) |
|
||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $5 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) |
|
||||
while IFS=$d read session_name window_number; do
|
||||
tmux resize-pane -t "${session_name}:${window_number}" -Z
|
||||
done
|
||||
|
@ -386,10 +369,6 @@ main() {
|
|||
restore_all_panes
|
||||
handle_session_0
|
||||
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"
|
||||
restore_all_pane_processes
|
||||
# below functions restore exact cursor positions
|
||||
|
|
|
@ -39,6 +39,8 @@ pane_format() {
|
|||
format+="${delimiter}"
|
||||
format+="#{pane_index}"
|
||||
format+="${delimiter}"
|
||||
format+="#{pane_title}"
|
||||
format+="${delimiter}"
|
||||
format+=":#{pane_current_path}"
|
||||
format+="${delimiter}"
|
||||
format+="#{pane_active}"
|
||||
|
@ -142,46 +144,6 @@ capture_pane_contents() {
|
|||
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() {
|
||||
local session_name="$1"
|
||||
tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" |
|
||||
|
@ -227,14 +189,14 @@ fetch_and_dump_grouped_sessions(){
|
|||
dump_panes() {
|
||||
local full_command
|
||||
dump_panes_raw |
|
||||
while IFS=$d read line_type session_name window_number window_active window_flags pane_index dir pane_active pane_command pane_pid history_size; do
|
||||
while IFS=$d read line_type session_name window_number window_active window_flags pane_index pane_title dir pane_active pane_command pane_pid history_size; do
|
||||
# not saving panes from grouped sessions
|
||||
if is_session_grouped "$session_name"; then
|
||||
continue
|
||||
fi
|
||||
full_command="$(pane_full_command $pane_pid)"
|
||||
dir=$(echo $dir | sed 's/ /\\ /') # escape all spaces in directory path
|
||||
echo "${line_type}${d}${session_name}${d}${window_number}${d}${window_active}${d}${window_flags}${d}${pane_index}${d}${dir}${d}${pane_active}${d}${pane_command}${d}:${full_command}"
|
||||
echo "${line_type}${d}${session_name}${d}${window_number}${d}${window_active}${d}${window_flags}${d}${pane_index}${d}${pane_title}${d}${dir}${d}${pane_active}${d}${pane_command}${d}:${full_command}"
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -259,18 +221,11 @@ dump_state() {
|
|||
dump_pane_contents() {
|
||||
local pane_contents_area="$(get_tmux_option "$pane_contents_area_option" "$default_pane_contents_area")"
|
||||
dump_panes_raw |
|
||||
while IFS=$d read line_type session_name window_number window_active window_flags pane_index dir pane_active pane_command pane_pid history_size; do
|
||||
while IFS=$d read line_type session_name window_number window_active window_flags pane_index pane_title dir pane_active pane_command pane_pid history_size; do
|
||||
capture_pane_contents "${session_name}:${window_number}.${pane_index}" "$history_size" "$pane_contents_area"
|
||||
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 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")"
|
||||
|
@ -300,9 +255,6 @@ save_all() {
|
|||
pane_contents_create_archive
|
||||
rm "$(pane_contents_dir "save")"/*
|
||||
fi
|
||||
if save_shell_history_option_on; then
|
||||
dump_shell_history
|
||||
fi
|
||||
remove_old_backups
|
||||
execute_hook "post-save-all"
|
||||
}
|
||||
|
|
|
@ -38,9 +38,6 @@ pane_contents_option="@resurrect-capture-pane-contents"
|
|||
pane_contents_area_option="@resurrect-pane-contents-area"
|
||||
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
|
||||
overwrite_option="@resurrect-never-overwrite"
|
||||
|
||||
|
|
Loading…
Reference in New Issue