Skip to content

Commit 1ad109d

Browse files
committed
Adds support for saving and restoring pane titles.
1 parent 027960a commit 1ad109d

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### master
44
- Proper handling of `automatic-rename` window option.
5+
- save and restore tmux pane title (breaking change: you have to re-save to be able to properly restore!)
56

67
### v3.0.0, 2021-08-30
78
- save and restore tmux pane contents (@laomaiweng)

scripts/restore.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ new_pane() {
170170
tmux split-window -t "${session_name}:${window_number}" -c "$dir"
171171
fi
172172
# minimize window so more panes can fit
173-
tmux resize-pane -t "${session_name}:${window_number}" -U "999"
173+
tmux resize-pane -t "${session_name}:${window_number}" -U "999"
174174
}
175175

176176
restore_pane() {
177177
local pane="$1"
178-
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
178+
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
179179
dir="$(remove_first_char "$dir")"
180180
pane_full_command="$(remove_first_char "$pane_full_command")"
181181
if [ "$session_name" == "0" ]; then
@@ -200,6 +200,8 @@ restore_pane() {
200200
else
201201
new_session "$session_name" "$window_number" "$dir" "$pane_index"
202202
fi
203+
# set pane title
204+
tmux select-pane -t "$session_name:$window_number.$pane_index" -T "$pane_title"
203205
done < <(echo "$pane")
204206
}
205207

@@ -323,7 +325,7 @@ restore_shell_history() {
323325
restore_all_pane_processes() {
324326
if restore_pane_processes_enabled; then
325327
local pane_full_command
326-
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $10 !~ "^:$" { print $2, $3, $6, $7, $10; }' $(last_resurrect_file) |
328+
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $6, $8, $11; }' $(last_resurrect_file) |
327329
while IFS=$d read -r session_name window_number pane_index dir pane_full_command; do
328330
dir="$(remove_first_char "$dir")"
329331
pane_full_command="$(remove_first_char "$pane_full_command")"
@@ -333,15 +335,15 @@ restore_all_pane_processes() {
333335
}
334336

335337
restore_active_pane_for_each_window() {
336-
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $8 == 1 { print $2, $3, $6; }' $(last_resurrect_file) |
338+
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $6; }' $(last_resurrect_file) |
337339
while IFS=$d read session_name window_number active_pane; do
338340
tmux switch-client -t "${session_name}:${window_number}"
339341
tmux select-pane -t "$active_pane"
340342
done
341343
}
342344

343345
restore_zoomed_windows() {
344-
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $5 ~ /Z/ && $8 == 1 { print $2, $3; }' $(last_resurrect_file) |
346+
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $5 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) |
345347
while IFS=$d read session_name window_number; do
346348
tmux resize-pane -t "${session_name}:${window_number}" -Z
347349
done

scripts/save.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pane_format() {
3939
format+="${delimiter}"
4040
format+="#{pane_index}"
4141
format+="${delimiter}"
42+
format+="#{pane_title}"
43+
format+="${delimiter}"
4244
format+=":#{pane_current_path}"
4345
format+="${delimiter}"
4446
format+="#{pane_active}"
@@ -227,14 +229,14 @@ fetch_and_dump_grouped_sessions(){
227229
dump_panes() {
228230
local full_command
229231
dump_panes_raw |
230-
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
232+
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
231233
# not saving panes from grouped sessions
232234
if is_session_grouped "$session_name"; then
233235
continue
234236
fi
235237
full_command="$(pane_full_command $pane_pid)"
236238
dir=$(echo $dir | sed 's/ /\\ /') # escape all spaces in directory path
237-
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}"
239+
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}"
238240
done
239241
}
240242

@@ -259,7 +261,7 @@ dump_state() {
259261
dump_pane_contents() {
260262
local pane_contents_area="$(get_tmux_option "$pane_contents_area_option" "$default_pane_contents_area")"
261263
dump_panes_raw |
262-
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
264+
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
263265
capture_pane_contents "${session_name}:${window_number}.${pane_index}" "$history_size" "$pane_contents_area"
264266
done
265267
}

0 commit comments

Comments
 (0)