mirror of
https://github.com/tmux-plugins/tmux-resurrect.git
synced 2024-12-26 01:28:49 +00:00
Leave window name handling to windows
Previously, window names were set when creating panes and were therefore saved with pane data. However, saving the names with window data is more intuitive and easier to manage. In addition, one can set the name and automatic-rename options in the same function, so one can make sure that renaming the windows will not overwrite the automatic-rename option.
This commit is contained in:
parent
80adb917c1
commit
6c9322aa99
@ -126,31 +126,29 @@ pane_creation_command() {
|
|||||||
new_window() {
|
new_window() {
|
||||||
local session_name="$1"
|
local session_name="$1"
|
||||||
local window_number="$2"
|
local window_number="$2"
|
||||||
local window_name="$3"
|
local dir="$3"
|
||||||
local dir="$4"
|
local pane_index="$4"
|
||||||
local pane_index="$5"
|
|
||||||
local pane_id="${session_name}:${window_number}.${pane_index}"
|
local pane_id="${session_name}:${window_number}.${pane_index}"
|
||||||
dir="${dir/#\~/$HOME}"
|
dir="${dir/#\~/$HOME}"
|
||||||
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
||||||
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
||||||
tmux new-window -d -t "${session_name}:${window_number}" -n "$window_name" -c "$dir" "$pane_creation_command"
|
tmux new-window -d -t "${session_name}:${window_number}" -c "$dir" "$pane_creation_command"
|
||||||
else
|
else
|
||||||
tmux new-window -d -t "${session_name}:${window_number}" -n "$window_name" -c "$dir"
|
tmux new-window -d -t "${session_name}:${window_number}" -c "$dir"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
new_session() {
|
new_session() {
|
||||||
local session_name="$1"
|
local session_name="$1"
|
||||||
local window_number="$2"
|
local window_number="$2"
|
||||||
local window_name="$3"
|
local dir="$3"
|
||||||
local dir="$4"
|
local pane_index="$4"
|
||||||
local pane_index="$5"
|
|
||||||
local pane_id="${session_name}:${window_number}.${pane_index}"
|
local pane_id="${session_name}:${window_number}.${pane_index}"
|
||||||
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
||||||
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
||||||
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$session_name" -n "$window_name" -c "$dir" "$pane_creation_command"
|
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$session_name" -c "$dir" "$pane_creation_command"
|
||||||
else
|
else
|
||||||
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$session_name" -n "$window_name" -c "$dir"
|
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$session_name" -c "$dir"
|
||||||
fi
|
fi
|
||||||
# change first window number if necessary
|
# change first window number if necessary
|
||||||
local created_window_num="$(first_window_num)"
|
local created_window_num="$(first_window_num)"
|
||||||
@ -162,9 +160,8 @@ new_session() {
|
|||||||
new_pane() {
|
new_pane() {
|
||||||
local session_name="$1"
|
local session_name="$1"
|
||||||
local window_number="$2"
|
local window_number="$2"
|
||||||
local window_name="$3"
|
local dir="$3"
|
||||||
local dir="$4"
|
local pane_index="$4"
|
||||||
local pane_index="$5"
|
|
||||||
local pane_id="${session_name}:${window_number}.${pane_index}"
|
local pane_id="${session_name}:${window_number}.${pane_index}"
|
||||||
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
if is_restoring_pane_contents && pane_contents_file_exists "$pane_id"; then
|
||||||
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
local pane_creation_command="$(pane_creation_command "$session_name" "$window_number" "$pane_index")"
|
||||||
@ -172,27 +169,24 @@ new_pane() {
|
|||||||
else
|
else
|
||||||
tmux split-window -t "${session_name}:${window_number}" -c "$dir"
|
tmux split-window -t "${session_name}:${window_number}" -c "$dir"
|
||||||
fi
|
fi
|
||||||
tmux rename-window -t "${session_name}:${window_number}" "$window_name"
|
|
||||||
# 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_name 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 dir pane_active pane_command pane_full_command; do
|
||||||
dir="$(remove_first_char "$dir")"
|
dir="$(remove_first_char "$dir")"
|
||||||
window_name="$(remove_first_char "$window_name")"
|
|
||||||
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
|
||||||
restored_session_0_true
|
restored_session_0_true
|
||||||
fi
|
fi
|
||||||
if pane_exists "$session_name" "$window_number" "$pane_index"; then
|
if pane_exists "$session_name" "$window_number" "$pane_index"; then
|
||||||
tmux rename-window -t "${session_name}:${window_number}" "$window_name"
|
|
||||||
if is_restoring_from_scratch; then
|
if is_restoring_from_scratch; then
|
||||||
# overwrite the pane
|
# overwrite the pane
|
||||||
# happens only for the first pane if it's the only registered pane for the whole tmux server
|
# happens only for the first pane if it's the only registered pane for the whole tmux server
|
||||||
local pane_id="$(tmux display-message -p -F "#{pane_id}" -t "$session_name:$window_number")"
|
local pane_id="$(tmux display-message -p -F "#{pane_id}" -t "$session_name:$window_number")"
|
||||||
new_pane "$session_name" "$window_number" "$window_name" "$dir" "$pane_index"
|
new_pane "$session_name" "$window_number" "$dir" "$pane_index"
|
||||||
tmux kill-pane -t "$pane_id"
|
tmux kill-pane -t "$pane_id"
|
||||||
else
|
else
|
||||||
# Pane exists, no need to create it!
|
# Pane exists, no need to create it!
|
||||||
@ -200,12 +194,11 @@ restore_pane() {
|
|||||||
register_existing_pane "$session_name" "$window_number" "$pane_index"
|
register_existing_pane "$session_name" "$window_number" "$pane_index"
|
||||||
fi
|
fi
|
||||||
elif window_exists "$session_name" "$window_number"; then
|
elif window_exists "$session_name" "$window_number"; then
|
||||||
tmux rename-window -t "${session_name}:${window_number}" "$window_name"
|
new_pane "$session_name" "$window_number" "$dir" "$pane_index"
|
||||||
new_pane "$session_name" "$window_number" "$window_name" "$dir" "$pane_index"
|
|
||||||
elif session_exists "$session_name"; then
|
elif session_exists "$session_name"; then
|
||||||
new_window "$session_name" "$window_number" "$window_name" "$dir" "$pane_index"
|
new_window "$session_name" "$window_number" "$dir" "$pane_index"
|
||||||
else
|
else
|
||||||
new_session "$session_name" "$window_number" "$window_name" "$dir" "$pane_index"
|
new_session "$session_name" "$window_number" "$dir" "$pane_index"
|
||||||
fi
|
fi
|
||||||
done < <(echo "$pane")
|
done < <(echo "$pane")
|
||||||
}
|
}
|
||||||
@ -292,9 +285,11 @@ handle_session_0() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_pane_layout_and_autonaming_for_each_window() {
|
restore_window_properties() {
|
||||||
\grep '^window' $(last_resurrect_file) |
|
\grep '^window' $(last_resurrect_file) |
|
||||||
while IFS=$d read line_type session_name window_number window_active window_flags window_layout automatic_rename; do
|
while IFS=$d read line_type session_name window_number window_name window_active window_flags window_layout automatic_rename; do
|
||||||
|
window_name="$(remove_first_char "$window_name")"
|
||||||
|
tmux rename-window -t "${session_name}:${window_number}" "$window_name"
|
||||||
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
|
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
|
||||||
if [ "${automatic_rename}" = ":" ]; then
|
if [ "${automatic_rename}" = ":" ]; then
|
||||||
tmux set-option -u -t "${session_name}:${window_number}" automatic-rename
|
tmux set-option -u -t "${session_name}:${window_number}" automatic-rename
|
||||||
@ -381,7 +376,7 @@ main() {
|
|||||||
execute_hook "pre-restore-all"
|
execute_hook "pre-restore-all"
|
||||||
restore_all_panes
|
restore_all_panes
|
||||||
handle_session_0
|
handle_session_0
|
||||||
restore_pane_layout_and_autonaming_for_each_window >/dev/null 2>&1
|
restore_window_properties >/dev/null 2>&1
|
||||||
execute_hook "pre-restore-history"
|
execute_hook "pre-restore-history"
|
||||||
if save_shell_history_option_on; then
|
if save_shell_history_option_on; then
|
||||||
restore_shell_history
|
restore_shell_history
|
||||||
|
@ -33,8 +33,6 @@ pane_format() {
|
|||||||
format+="${delimiter}"
|
format+="${delimiter}"
|
||||||
format+="#{window_index}"
|
format+="#{window_index}"
|
||||||
format+="${delimiter}"
|
format+="${delimiter}"
|
||||||
format+=":#{window_name}"
|
|
||||||
format+="${delimiter}"
|
|
||||||
format+="#{window_active}"
|
format+="#{window_active}"
|
||||||
format+="${delimiter}"
|
format+="${delimiter}"
|
||||||
format+=":#{window_flags}"
|
format+=":#{window_flags}"
|
||||||
@ -61,6 +59,8 @@ window_format() {
|
|||||||
format+="${delimiter}"
|
format+="${delimiter}"
|
||||||
format+="#{window_index}"
|
format+="#{window_index}"
|
||||||
format+="${delimiter}"
|
format+="${delimiter}"
|
||||||
|
format+="#{window_name}"
|
||||||
|
format+="${delimiter}"
|
||||||
format+="#{window_active}"
|
format+="#{window_active}"
|
||||||
format+="${delimiter}"
|
format+="${delimiter}"
|
||||||
format+=":#{window_flags}"
|
format+=":#{window_flags}"
|
||||||
@ -227,20 +227,20 @@ 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_name 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 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_name}${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}${dir}${d}${pane_active}${d}${pane_command}${d}:${full_command}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
dump_windows() {
|
dump_windows() {
|
||||||
dump_windows_raw |
|
dump_windows_raw |
|
||||||
while IFS=$d read line_type session_name window_index window_active window_flags window_layout; do
|
while IFS=$d read line_type session_name window_index window_name window_active window_flags window_layout; do
|
||||||
# not saving windows from grouped sessions
|
# not saving windows from grouped sessions
|
||||||
if is_session_grouped "$session_name"; then
|
if is_session_grouped "$session_name"; then
|
||||||
continue
|
continue
|
||||||
@ -248,7 +248,7 @@ dump_windows() {
|
|||||||
automatic_rename="$(tmux show-window-options -vt "${session_name}:${window_index}" automatic-rename)"
|
automatic_rename="$(tmux show-window-options -vt "${session_name}:${window_index}" automatic-rename)"
|
||||||
# If the option was unset, place the ":" placeholder instead.
|
# If the option was unset, place the ":" placeholder instead.
|
||||||
[ -z "${automatic_rename}" ] && automatic_rename=":"
|
[ -z "${automatic_rename}" ] && automatic_rename=":"
|
||||||
echo "${line_type}${d}${session_name}${d}${window_index}${d}${window_active}${d}${window_flags}${d}${window_layout}${d}${automatic_rename}"
|
echo "${line_type}${d}${session_name}${d}${window_index}${d}${window_name}${d}${window_active}${d}${window_flags}${d}${window_layout}${d}${automatic_rename}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user