Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restoring pane title #342

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions scripts/restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ new_pane() {

restore_pane() {
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_name window_active window_flags pane_index pane_title dir pane_active pane_command pane_full_command; do
dir="$(remove_first_char "$dir")"
window_name="$(remove_first_char "$window_name")"
pane_full_command="$(remove_first_char "$pane_full_command")"
Expand All @@ -194,6 +194,7 @@ restore_pane() {
else
new_session "$session_name" "$window_number" "$window_name" "$dir" "$pane_index"
fi
tmux select-pane -t "$session_name":"$window_number"."$pane_index" -T "${pane_title}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of naming the pane with a standalone command, can we somehow set the correct pane_title when the pane is created?

done < <(echo "$pane")
}

Expand Down Expand Up @@ -298,7 +299,7 @@ restore_shell_history() {
restore_all_pane_processes() {
if restore_pane_processes_enabled; then
local pane_full_command
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $8, $11; }' $(last_resurrect_file) |
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $11 !~ "^:$" { print $2, $3, $7, $9, $12; }' $(last_resurrect_file) |
while IFS=$d read -r session_name window_number pane_index dir pane_full_command; do
dir="$(remove_first_char "$dir")"
pane_full_command="$(remove_first_char "$pane_full_command")"
Expand All @@ -308,15 +309,15 @@ restore_all_pane_processes() {
}

restore_active_pane_for_each_window() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $9 == 1 { print $2, $3, $7; }' $(last_resurrect_file) |
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $10 == 1 { print $2, $3, $7; }' $(last_resurrect_file) |
while IFS=$d read session_name window_number active_pane; do
tmux switch-client -t "${session_name}:${window_number}"
tmux select-pane -t "$active_pane"
done
}

restore_zoomed_windows() {
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $6 ~ /Z/ && $9 == 1 { print $2, $3; }' $(last_resurrect_file) |
awk 'BEGIN { FS="\t"; OFS="\t" } /^pane/ && $6 ~ /Z/ && $10 == 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
Expand Down
8 changes: 5 additions & 3 deletions scripts/save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pane_format() {
format+="#{pane_pid}"
format+="${delimiter}"
format+="#{history_size}"
format+="${delimiter}"
format+="#{pane_title}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if we grouped all pane_ interpolations together? Maybe add pane_title after pane_index?

This will be a breaking change when performing a restore with the old resurrect file, but that's a separate concern.

echo "$format"
}

Expand Down Expand Up @@ -227,14 +229,14 @@ fetch_and_dump_grouped_sessions(){
dump_panes() {
local full_command
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_name window_active window_flags pane_index dir pane_active pane_command pane_pid history_size pane_title; do
# not saving panes from grouped sessions
if is_session_grouped "$session_name"; then
continue
fi
full_command="$(pane_full_command $pane_pid)"
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_name}${d}${window_active}${d}${window_flags}${d}${pane_index}${d}${pane_title}${d}${dir}${d}${pane_active}${d}${pane_command}${d}:${full_command}"
done
}

Expand Down Expand Up @@ -313,7 +315,7 @@ main() {
start_spinner "Saving..." "Tmux environment saved!"
fi
save_all
if show_output; then
if show_output; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please use tabs for indentation?

I'm also not happy with tabs and would like to change to two-space indentation, but I need help from someone that's willing to do that for all the repos in tmux-plugins github org.

stop_spinner
display_message "Tmux environment saved!"
fi
Expand Down