Unverified Commit 95ec3c1d authored by Bruno Sutic's avatar Bruno Sutic
Browse files

Save and restore active and alternate windows for grouped sessions

parent 5dc22a4a
......@@ -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
......
......@@ -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
......
......@@ -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
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment