Added support for saving and restoring buffers for panes running Bash.
parent
9eae48b87e
commit
8d7974da53
|
@ -157,6 +157,15 @@ foreground when saving. `tmux-resurrect` will send history write command
|
|||
to each such pane. To prevent these commands from being added to history themselves,
|
||||
add `HISTCONTROL=ignoreboth` to your `.bashrc` (this is set by default in Ubuntu).
|
||||
|
||||
#### Restoring tmux buffers (experimental)
|
||||
|
||||
In `.tmux.conf`:
|
||||
|
||||
set -g @resurrect-save-tmux-buffers 'on'
|
||||
|
||||
Scrollback buffers 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. On save, `tmux-resurrect` will capture and save the scrollback buffer from each pane; on restore, `tmux-resurrect` will `cat` each buffer file back to its restored pane. To prevent the latter command from being added to history, add `HISTCONTROL=ignoreboth` to your `.bashrc` (this is set by default in Ubuntu).
|
||||
|
||||
### Other goodies
|
||||
|
||||
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin for
|
||||
|
|
|
@ -54,6 +54,11 @@ save_bash_history_option_on() {
|
|||
[ "$option" == "on" ]
|
||||
}
|
||||
|
||||
save_tmux_buffers_option_on() {
|
||||
local option="$(get_tmux_option "$save_tmux_buffers_option" "off")"
|
||||
[ "$option" == "on" ]
|
||||
}
|
||||
|
||||
# path helpers
|
||||
|
||||
resurrect_dir() {
|
||||
|
@ -74,6 +79,11 @@ resurrect_history_file() {
|
|||
echo "$(resurrect_dir)/bash_history-${pane_id}"
|
||||
}
|
||||
|
||||
resurrect_buffer_file() {
|
||||
local pane_id="$1"
|
||||
echo "$(resurrect_dir)/tmux_buffer-${pane_id}"
|
||||
}
|
||||
|
||||
restore_zoomed_windows() {
|
||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $6 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) |
|
||||
while IFS=$'\t' read session_name window_number; do
|
||||
|
|
|
@ -156,6 +156,23 @@ restore_shell_history() {
|
|||
done
|
||||
}
|
||||
|
||||
restore_tmux_buffers() {
|
||||
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ { print $2, $3, $7, $10; }' $(last_resurrect_file) |
|
||||
while IFS=$'\t' read session_name window_number pane_index pane_command; do
|
||||
if ! is_pane_registered_as_existing "$session_name" "$window_number" "$pane_index"; then
|
||||
if [ "$pane_command" = "bash" ]; then
|
||||
local pane_id="$session_name:$window_number.$pane_index"
|
||||
local buffer_file="$(resurrect_buffer_file "${pane_id}")"
|
||||
# space before 'cat' is intentional and prevents the command from
|
||||
# being added to history (provided HISTCONTROL=ignorespace/ignoreboth
|
||||
# has been set in bashrc.
|
||||
tmux send-keys -t "${pane_id}" "clear && tmux clear-history" C-m
|
||||
tmux send-keys -t "${pane_id}" " cat ${buffer_file}" C-m
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
restore_all_pane_processes() {
|
||||
if restore_pane_processes_enabled; then
|
||||
local pane_full_command
|
||||
|
@ -207,6 +224,9 @@ main() {
|
|||
if save_bash_history_option_on; then
|
||||
restore_shell_history
|
||||
fi
|
||||
if save_tmux_buffers_option_on; then
|
||||
restore_tmux_buffers
|
||||
fi
|
||||
restore_all_pane_processes
|
||||
# below functions restore exact cursor positions
|
||||
restore_active_pane_for_each_window
|
||||
|
|
|
@ -97,6 +97,21 @@ save_shell_history() {
|
|||
fi
|
||||
}
|
||||
|
||||
save_tmux_buffer() {
|
||||
local pane_id="$1"
|
||||
local pane_command="$2"
|
||||
local full_command="$3"
|
||||
local mode_keys=$(tmux show-window-options -g | awk '/^mode-keys/ {print $2}')
|
||||
local save_command=""
|
||||
local buffer_file="$(resurrect_buffer_file "${pane_id}")"
|
||||
if [ "$pane_command" = "bash" ] && [ "$full_command" = ":" ]; then
|
||||
tmux capture-pane -S -32768 \; save-buffer -b 0 "${buffer_file}" \; delete-buffer -b 0
|
||||
if [ ! -s "${buffer_file}" ] ;then
|
||||
rm "${buffer_file}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# translates pane pid to process command running inside a pane
|
||||
dump_panes() {
|
||||
local full_command
|
||||
|
@ -128,6 +143,13 @@ dump_bash_history() {
|
|||
done
|
||||
}
|
||||
|
||||
dump_tmux_buffers() {
|
||||
dump_panes |
|
||||
while IFS=$'\t' read line_type session_name window_number window_name window_active window_flags pane_index dir pane_active pane_command full_command; do
|
||||
save_tmux_buffer "$session_name:$window_number.$pane_index" "$pane_command" "$full_command"
|
||||
done
|
||||
}
|
||||
|
||||
save_all() {
|
||||
local resurrect_file_path="$(resurrect_file_path)"
|
||||
mkdir -p "$(resurrect_dir)"
|
||||
|
@ -138,6 +160,9 @@ save_all() {
|
|||
if save_bash_history_option_on; then
|
||||
dump_bash_history
|
||||
fi
|
||||
if save_tmux_buffers_option_on; then
|
||||
dump_tmux_buffers
|
||||
fi
|
||||
restore_zoomed_windows
|
||||
}
|
||||
|
||||
|
|
|
@ -28,3 +28,5 @@ save_command_strategy_option="@resurrect-save-command-strategy"
|
|||
default_save_command_strategy="ps"
|
||||
|
||||
bash_history_option="@resurrect-save-bash-history"
|
||||
|
||||
save_tmux_buffers_option="@resurrect-save-tmux-buffers"
|
||||
|
|
Loading…
Reference in New Issue