Merge pull request #431 from Hologos/feature/save-pane-title

Adds support for saving and restoring pane titles.
This commit is contained in:
Bruno Sutic 2022-04-10 08:39:15 +02:00 committed by GitHub
commit 5b5e6ca7b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 8 deletions

View File

@ -2,6 +2,7 @@
### master ### master
- Proper handling of `automatic-rename` window option. - 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 ### v3.0.0, 2021-08-30
- save and restore tmux pane contents (@laomaiweng) - save and restore tmux pane contents (@laomaiweng)

View File

@ -170,12 +170,12 @@ new_pane() {
tmux split-window -t "${session_name}:${window_number}" -c "$dir" tmux split-window -t "${session_name}:${window_number}" -c "$dir"
fi fi
# minimize window so more panes can fit # 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() { restore_pane() {
local pane="$1" 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")" dir="$(remove_first_char "$dir")"
pane_full_command="$(remove_first_char "$pane_full_command")" pane_full_command="$(remove_first_char "$pane_full_command")"
if [ "$session_name" == "0" ]; then if [ "$session_name" == "0" ]; then
@ -200,6 +200,8 @@ restore_pane() {
else else
new_session "$session_name" "$window_number" "$dir" "$pane_index" new_session "$session_name" "$window_number" "$dir" "$pane_index"
fi fi
# set pane title
tmux select-pane -t "$session_name:$window_number.$pane_index" -T "$pane_title"
done < <(echo "$pane") done < <(echo "$pane")
} }
@ -323,7 +325,7 @@ restore_shell_history() {
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
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 while IFS=$d read -r session_name window_number pane_index dir pane_full_command; do
dir="$(remove_first_char "$dir")" dir="$(remove_first_char "$dir")"
pane_full_command="$(remove_first_char "$pane_full_command")" pane_full_command="$(remove_first_char "$pane_full_command")"
@ -333,7 +335,7 @@ restore_all_pane_processes() {
} }
restore_active_pane_for_each_window() { 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 while IFS=$d read session_name window_number active_pane; do
tmux switch-client -t "${session_name}:${window_number}" tmux switch-client -t "${session_name}:${window_number}"
tmux select-pane -t "$active_pane" tmux select-pane -t "$active_pane"
@ -341,7 +343,7 @@ restore_active_pane_for_each_window() {
} }
restore_zoomed_windows() { 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 while IFS=$d read session_name window_number; do
tmux resize-pane -t "${session_name}:${window_number}" -Z tmux resize-pane -t "${session_name}:${window_number}" -Z
done done

View File

@ -39,6 +39,8 @@ pane_format() {
format+="${delimiter}" format+="${delimiter}"
format+="#{pane_index}" format+="#{pane_index}"
format+="${delimiter}" format+="${delimiter}"
format+="#{pane_title}"
format+="${delimiter}"
format+=":#{pane_current_path}" format+=":#{pane_current_path}"
format+="${delimiter}" format+="${delimiter}"
format+="#{pane_active}" format+="#{pane_active}"
@ -227,14 +229,14 @@ fetch_and_dump_grouped_sessions(){
dump_panes() { dump_panes() {
local full_command local full_command
dump_panes_raw | 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 # not saving panes from grouped sessions
if is_session_grouped "$session_name"; then if is_session_grouped "$session_name"; then
continue continue
fi fi
full_command="$(pane_full_command $pane_pid)" full_command="$(pane_full_command $pane_pid)"
dir=$(echo $dir | sed 's/ /\\ /') # escape all spaces in directory path 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 done
} }
@ -259,7 +261,7 @@ dump_state() {
dump_pane_contents() { dump_pane_contents() {
local pane_contents_area="$(get_tmux_option "$pane_contents_area_option" "$default_pane_contents_area")" local pane_contents_area="$(get_tmux_option "$pane_contents_area_option" "$default_pane_contents_area")"
dump_panes_raw | 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" capture_pane_contents "${session_name}:${window_number}.${pane_index}" "$history_size" "$pane_contents_area"
done done
} }