|
|
|
@ -16,6 +16,8 @@ d=$'\t'
|
|
|
|
|
# is also not restored. That makes the restoration process more idempotent.
|
|
|
|
|
EXISTING_PANES_VAR=""
|
|
|
|
|
|
|
|
|
|
RESTORING_FROM_SCRATCH="false"
|
|
|
|
|
|
|
|
|
|
is_line_type() {
|
|
|
|
|
local line_type="$1"
|
|
|
|
|
local line="$2"
|
|
|
|
@ -56,6 +58,14 @@ is_pane_registered_as_existing() {
|
|
|
|
|
[[ "$EXISTING_PANES_VAR" =~ "$pane_custom_id" ]]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_from_scratch_true() {
|
|
|
|
|
RESTORING_FROM_SCRATCH="true"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
is_restoring_from_scratch() {
|
|
|
|
|
[ "$RESTORING_FROM_SCRATCH" == "true" ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window_exists() {
|
|
|
|
|
local session_name="$1"
|
|
|
|
|
local window_number="$2"
|
|
|
|
@ -114,9 +124,17 @@ restore_pane() {
|
|
|
|
|
window_name="$(remove_first_char "$window_name")"
|
|
|
|
|
pane_full_command="$(remove_first_char "$pane_full_command")"
|
|
|
|
|
if pane_exists "$session_name" "$window_number" "$pane_index"; then
|
|
|
|
|
# Pane exists, no need to create it!
|
|
|
|
|
# Pane existence is registered. Later, it's process also isn't restored.
|
|
|
|
|
register_existing_pane "$session_name" "$window_number" "$pane_index"
|
|
|
|
|
if is_restoring_from_scratch; then
|
|
|
|
|
# overwrite the pane
|
|
|
|
|
# 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")"
|
|
|
|
|
new_pane "$session_name" "$window_number" "$window_name" "$dir"
|
|
|
|
|
tmux kill-pane -t "$pane_id"
|
|
|
|
|
else
|
|
|
|
|
# Pane exists, no need to create it!
|
|
|
|
|
# Pane existence is registered. Later, its process also won't be restored.
|
|
|
|
|
register_existing_pane "$session_name" "$window_number" "$pane_index"
|
|
|
|
|
fi
|
|
|
|
|
elif window_exists "$session_name" "$window_number"; then
|
|
|
|
|
new_pane "$session_name" "$window_number" "$window_name" "$dir"
|
|
|
|
|
elif session_exists "$session_name"; then
|
|
|
|
@ -136,7 +154,48 @@ restore_state() {
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_grouped_session() {
|
|
|
|
|
local grouped_session="$1"
|
|
|
|
|
echo "$grouped_session" |
|
|
|
|
|
while IFS=$d read line_type grouped_session original_session alternate_window active_window; do
|
|
|
|
|
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$grouped_session" -t "$original_session"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_active_and_alternate_windows_for_grouped_sessions() {
|
|
|
|
|
local grouped_session="$1"
|
|
|
|
|
echo "$grouped_session" |
|
|
|
|
|
while IFS=$d read line_type grouped_session original_session alternate_window_index active_window_index; do
|
|
|
|
|
alternate_window_index="$(remove_first_char "$alternate_window_index")"
|
|
|
|
|
active_window_index="$(remove_first_char "$active_window_index")"
|
|
|
|
|
if [ -n "$alternate_window_index" ]; then
|
|
|
|
|
tmux switch-client -t "${grouped_session}:${alternate_window_index}"
|
|
|
|
|
fi
|
|
|
|
|
if [ -n "$active_window_index" ]; then
|
|
|
|
|
tmux switch-client -t "${grouped_session}:${active_window_index}"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
never_ever_overwrite() {
|
|
|
|
|
local overwrite_option_value="$(get_tmux_option "$overwrite_option" "")"
|
|
|
|
|
[ -n "$overwrite_option_value" ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
detect_if_restoring_from_scratch() {
|
|
|
|
|
if never_ever_overwrite; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
local total_number_of_panes="$(tmux list-panes -a | wc -l | sed 's/ //g')"
|
|
|
|
|
if [ "$total_number_of_panes" -eq 1 ]; then
|
|
|
|
|
restore_from_scratch_true
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# functions called from main (ordered)
|
|
|
|
|
|
|
|
|
|
restore_all_panes() {
|
|
|
|
|
detect_if_restoring_from_scratch
|
|
|
|
|
while read line; do
|
|
|
|
|
if is_line_type "pane" "$line"; then
|
|
|
|
|
restore_pane "$line"
|
|
|
|
@ -144,6 +203,13 @@ restore_all_panes() {
|
|
|
|
|
done < $(last_resurrect_file)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_pane_layout_for_each_window() {
|
|
|
|
|
\grep '^window' $(last_resurrect_file) |
|
|
|
|
|
while IFS=$d read line_type session_name window_number window_active window_flags window_layout; do
|
|
|
|
|
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_shell_history() {
|
|
|
|
|
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ { print $2, $3, $7, $10; }' $(last_resurrect_file) |
|
|
|
|
|
while IFS=$d read session_name window_number pane_index pane_command; do
|
|
|
|
@ -171,13 +237,6 @@ restore_all_pane_processes() {
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_pane_layout_for_each_window() {
|
|
|
|
|
\grep '^window' $(last_resurrect_file) |
|
|
|
|
|
while IFS=$d read line_type session_name window_number window_active window_flags window_layout; do
|
|
|
|
|
tmux select-layout -t "${session_name}:${window_number}" "$window_layout"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_active_pane_for_each_window() {
|
|
|
|
|
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $7; }' $(last_resurrect_file) |
|
|
|
|
|
while IFS=$d read session_name window_number active_pane; do
|
|
|
|
@ -186,27 +245,11 @@ restore_active_pane_for_each_window() {
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_grouped_session() {
|
|
|
|
|
local grouped_session="$1"
|
|
|
|
|
echo "$grouped_session" |
|
|
|
|
|
while IFS=$d read line_type grouped_session original_session alternate_window active_window; do
|
|
|
|
|
TMUX="" tmux -S "$(tmux_socket)" new-session -d -s "$grouped_session" -t "$original_session"
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_active_and_alternate_windows_for_grouped_sessions() {
|
|
|
|
|
local grouped_session="$1"
|
|
|
|
|
echo "$grouped_session" |
|
|
|
|
|
while IFS=$d read line_type grouped_session original_session alternate_window_index active_window_index; do
|
|
|
|
|
alternate_window_index="$(remove_first_char "$alternate_window_index")"
|
|
|
|
|
active_window_index="$(remove_first_char "$active_window_index")"
|
|
|
|
|
if [ -n "$alternate_window_index" ]; then
|
|
|
|
|
tmux switch-client -t "${grouped_session}:${alternate_window_index}"
|
|
|
|
|
fi
|
|
|
|
|
if [ -n "$active_window_index" ]; then
|
|
|
|
|
tmux switch-client -t "${grouped_session}:${active_window_index}"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
restore_zoomed_windows() {
|
|
|
|
|
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $6 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) |
|
|
|
|
|
while IFS=$d read session_name window_number; do
|
|
|
|
|
tmux resize-pane -t "${session_name}:${window_number}" -Z
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
restore_grouped_sessions() {
|
|
|
|
|