Save and restore active and alternate windows for grouped sessions

pull/73/head
Bruno Sutic 2015-02-09 15:57:48 +01:00
parent 5dc22a4a9b
commit 95ec3c1d9b
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
3 changed files with 28 additions and 3 deletions

View File

@ -4,6 +4,7 @@
- add link to the wiki page for "first pane/window issue" to the README as well
as other tweaks
- save and restore grouped sessions (used with multi-monitor workflow)
- save and restore active and alternate windows in grouped sessions
### v1.5.0, 2014-11-09
- add support for restoring neovim sessions

View File

@ -186,15 +186,25 @@ restore_active_pane_for_each_window() {
restore_grouped_session() {
local grouped_session="$1"
echo "$grouped_session" |
while IFS=$'\t' read line_type grouped_session original_session; do
while IFS=$'\t' 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=$'\t' read line_type grouped_session original_session alternate_window_index active_window_index; do
tmux switch-client -t "${grouped_session}:${alternate_window_index}"
tmux switch-client -t "${grouped_session}:${active_window_index}"
done
}
restore_grouped_sessions() {
while read line; do
if is_line_type "grouped_session" "$line"; then
restore_grouped_session "$line"
restore_active_and_alternate_windows_for_grouped_sessions "$line"
fi
done < $(last_resurrect_file)
}
@ -227,7 +237,7 @@ main() {
# below functions restore exact cursor positions
restore_active_pane_for_each_window
restore_zoomed_windows
restore_grouped_sessions
restore_grouped_sessions # also restores active and alt windows for grouped sessions
restore_active_and_alternate_windows
restore_active_and_alternate_sessions
stop_spinner

View File

@ -114,6 +114,18 @@ save_shell_history() {
fi
}
get_active_window_index() {
local session_name="$1"
tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" |
awk '$1 ~ /\*/ { print $2; }'
}
get_alternate_window_index() {
local session_name="$1"
tmux list-windows -t "$session_name" -F "#{window_flags} #{window_index}" |
awk '$1 ~ /-/ { print $2; }'
}
dump_grouped_sessions() {
local current_session_group=""
local original_session
@ -128,7 +140,9 @@ dump_grouped_sessions() {
current_session_group="$session_group"
else
# this session "points" to the original session
echo "grouped_session${d}${session_name}${d}${original_session}"
active_window_index="$(get_active_window_index "$session_name")"
alternate_window_index="$(get_alternate_window_index "$session_name")"
echo "grouped_session${d}${session_name}${d}${original_session}${d}${alternate_window_index}${d}${active_window_index}"
fi
done
}