Skip to content

Commit 2e6855e

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

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
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: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,20 +162,23 @@ new_pane() {
162162
local window_number="$2"
163163
local dir="$3"
164164
local pane_index="$4"
165+
local pane_title="$5"
165166
local pane_id="${session_name}:${window_number}.${pane_index}"
166167
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
167168
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
168169
tmux split-window -t "${session_name}:${window_number}" -c "$dir" "$pane_creation_command"
169170
else
170171
tmux split-window -t "${session_name}:${window_number}" -c "$dir"
171172
fi
173+
# set pane title
174+
tmux select-pane -t "${session_name}:${window_number}.${pane_index}" -T "${pane_title}"
172175
# minimize window so more panes can fit
173-
tmux resize-pane -t "${session_name}:${window_number}" -U "999"
176+
tmux resize-pane -t "${session_name}:${window_number}" -U "999"
174177
}
175178

176179
restore_pane() {
177180
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
181+
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
179182
dir="$(remove_first_char "$dir")"
180183
pane_full_command="$(remove_first_char "$pane_full_command")"
181184
if [ "$session_name" == "0" ]; then
@@ -186,15 +189,15 @@ restore_pane() {
186189
# overwrite the pane
187190
# happens only for the first pane if it's the only registered pane for the whole tmux server
188191
local pane_id="$(tmux display-message -p -F "#{pane_id}" -t "$session_name:$window_number")"
189-
new_pane "$session_name" "$window_number" "$dir" "$pane_index"
192+
new_pane "$session_name" "$window_number" "$dir" "$pane_index" "$pane_title"
190193
tmux kill-pane -t "$pane_id"
191194
else
192195
# Pane exists, no need to create it!
193196
# Pane existence is registered. Later, its process also won't be restored.
194197
register_existing_pane "$session_name" "$window_number" "$pane_index"
195198
fi
196199
elif window_exists "$session_name" "$window_number"; then
197-
new_pane "$session_name" "$window_number" "$dir" "$pane_index"
200+
new_pane "$session_name" "$window_number" "$dir" "$pane_index" "$pane_title"
198201
elif session_exists "$session_name"; then
199202
new_window "$session_name" "$window_number" "$dir" "$pane_index"
200203
else
@@ -302,7 +305,7 @@ restore_window_properties() {
302305
}
303306

304307
restore_shell_history() {
305-
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ { print $2, $3, $6, $9; }' $(last_resurrect_file) |
308+
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ { print $2, $3, $6, $10; }' $(last_resurrect_file) |
306309
while IFS=$d read session_name window_number pane_index pane_command; do
307310
if ! is_pane_registered_as_existing "$session_name" "$window_number" "$pane_index"; then
308311
local pane_id="$session_name:$window_number.$pane_index"
@@ -323,7 +326,7 @@ restore_shell_history() {
323326
restore_all_pane_processes() {
324327
if restore_pane_processes_enabled; then
325328
local pane_full_command
326-
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $10 !~ "^:$" { print $2, $3, $6, $7, $10; }' $(last_resurrect_file) |
329+
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $6, $8, $11; }' $(last_resurrect_file) |
327330
while IFS=$d read -r session_name window_number pane_index dir pane_full_command; do
328331
dir="$(remove_first_char "$dir")"
329332
pane_full_command="$(remove_first_char "$pane_full_command")"
@@ -333,15 +336,15 @@ restore_all_pane_processes() {
333336
}
334337

335338
restore_active_pane_for_each_window() {
336-
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $8 == 1 { print $2, $3, $6; }' $(last_resurrect_file) |
339+
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $6; }' $(last_resurrect_file) |
337340
while IFS=$d read session_name window_number active_pane; do
338341
tmux switch-client -t "${session_name}:${window_number}"
339342
tmux select-pane -t "$active_pane"
340343
done
341344
}
342345

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

scripts/save.sh

Lines changed: 6 additions & 4 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,14 +261,14 @@ 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
}
266268

267269
dump_shell_history() {
268270
dump_panes |
269-
while IFS=$d read line_type session_name window_number window_active window_flags pane_index dir pane_active pane_command full_command; do
271+
while IFS=$d read line_type session_name window_number window_active window_flags pane_index pane_title dir pane_active pane_command full_command; do
270272
save_shell_history "$session_name:$window_number.$pane_index" "$pane_command" "$full_command"
271273
done
272274
}

0 commit comments

Comments
 (0)