Restore pane layout for each window

Close #2
This commit is contained in:
Bruno Sutic 2014-08-26 20:19:34 +02:00
parent a649614a20
commit 8051fb9d36
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
3 changed files with 33 additions and 2 deletions

View File

@ -1,6 +1,7 @@
# Changelog
### master
- restore pane layout for each window
### v0.0.3, 2014-08-26
- save and restore current and alternate session

View File

@ -104,6 +104,13 @@ restore_all_sessions() {
done < $(last_session_path)
}
restore_pane_layout_for_each_window() {
\grep '^window' $(last_session_path) |
while IFS=$'\t' 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/ && $7 != 0 && $9 == 1 { print $2, $3, $7; }' $(last_session_path) |
while IFS=$'\t' read session_name window_number active_pane; do
@ -132,6 +139,7 @@ main() {
if supported_tmux_version_ok; then
check_saved_session_exists
restore_all_sessions
restore_pane_layout_for_each_window
restore_active_pane_for_each_window
restore_active_and_alternate_windows
restore_active_and_alternate_sessions

View File

@ -27,6 +27,23 @@ pane_format() {
echo "$format"
}
window_format() {
local delimiter=$'\t'
local format
format+="window"
format+="${delimiter}"
format+="#{session_name}"
format+="${delimiter}"
format+="#{window_index}"
format+="${delimiter}"
format+="#{window_active}"
format+="${delimiter}"
format+=":#{window_flags}"
format+="${delimiter}"
format+="#{window_layout}"
echo "$format"
}
state_format() {
local delimiter=$'\t'
local format
@ -42,6 +59,10 @@ dump_panes() {
tmux list-panes -a -F "$(pane_format)"
}
dump_windows() {
tmux list-windows -a -F "$(window_format)"
}
dump_state() {
tmux display-message -p "$(state_format)"
}
@ -49,8 +70,9 @@ dump_state() {
save_all_sessions() {
local session_path="$(session_path)"
mkdir -p "$(sessions_dir)"
dump_panes > $session_path
dump_state >> $session_path
dump_panes > $session_path
dump_windows >> $session_path
dump_state >> $session_path
ln -fs "$session_path" "$(last_session_path)"
display_message "Saved all Tmux sessions!"
}