Make pane restorations idempotent

This commit is contained in:
Bruno Sutic 2014-08-29 12:49:06 +02:00
parent bd13c9bae8
commit 9a6e4a1a2c
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
2 changed files with 15 additions and 3 deletions

View File

@ -3,6 +3,8 @@
### master ### master
- bugfix: when top is running the pane `$PWD` can't be saved. This was causing - bugfix: when top is running the pane `$PWD` can't be saved. This was causing
issues during the restore and is now fixed. issues during the restore and is now fixed.
- restoring sessions multiple times messes up the whole environment - new panes
are all around. This is now fixed - pane restorations are now idempotent.
### v0.2.0, 2014-08-29 ### v0.2.0, 2014-08-29
- bugfix: with vim 'session' strategy, if the session file does not exist - make - bugfix: with vim 'session' strategy, if the session file does not exist - make

View File

@ -22,6 +22,14 @@ check_saved_session_exists() {
fi fi
} }
pane_exists() {
local session_name="$1"
local window_number="$2"
local pane_index="$3"
tmux list-panes -t "${session_name}:${window_number}" -F "#{pane_index}" 2>/dev/null |
\grep -q "^$pane_index$"
}
window_exists() { window_exists() {
local session_name="$1" local session_name="$1"
local window_number="$2" local window_number="$2"
@ -78,7 +86,9 @@ restore_pane() {
dir="$(remove_first_char "$dir")" dir="$(remove_first_char "$dir")"
window_name="$(remove_first_char "$window_name")" window_name="$(remove_first_char "$window_name")"
pane_full_command="$(remove_first_char "$pane_full_command")" pane_full_command="$(remove_first_char "$pane_full_command")"
if window_exists "$session_name" "$window_number"; then if pane_exists "$session_name" "$window_number" "$pane_index"; then
true # pane exists, no need to create it!
elif window_exists "$session_name" "$window_number"; then
new_pane "$session_name" "$window_number" "$window_name" "$dir" new_pane "$session_name" "$window_number" "$window_name" "$dir"
elif session_exists "$session_name"; then elif session_exists "$session_name"; then
new_window "$session_name" "$window_number" "$window_name" "$dir" new_window "$session_name" "$window_number" "$window_name" "$dir"
@ -97,7 +107,7 @@ restore_state() {
done done
} }
restore_all_sessions() { restore_all_panes() {
while read line; do while read line; do
if is_line_type "pane" "$line"; then if is_line_type "pane" "$line"; then
restore_pane "$line" restore_pane "$line"
@ -151,7 +161,7 @@ restore_active_and_alternate_sessions() {
main() { main() {
if supported_tmux_version_ok && check_saved_session_exists; then if supported_tmux_version_ok && check_saved_session_exists; then
start_spinner start_spinner
restore_all_sessions restore_all_panes
restore_all_pane_processes restore_all_pane_processes
restore_pane_layout_for_each_window >/dev/null 2>&1 restore_pane_layout_for_each_window >/dev/null 2>&1
# below functions restore exact cursor positions # below functions restore exact cursor positions