From d5d87d3ab21e4e0916a36e1c86ca4534c2b58fac Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 6 Sep 2012 22:11:51 +0100 Subject: [PATCH] Fix issue #7 Instead of assuming that the default created window in a new session has a index of `0`, we now check window index for the session with Tmux's list-windows command. Additionally, the default window is now moved to index `999` instead of `99`, cause I'm paranoid and probably stupid :) --- lib/layout-helpers.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/layout-helpers.sh b/lib/layout-helpers.sh index 4c4846e..57bbbe0 100644 --- a/lib/layout-helpers.sh +++ b/lib/layout-helpers.sh @@ -182,9 +182,10 @@ initialize_session() { fi # In order to ensure only specified windows are created, we move the - # default window to position 99, and later remove it with the - # `finalize_session` function. - tmux move-window -s "$session:0" -t "$session:99" + # default window to position 999, and later remove it with the + # `finalize_and_go_to_session` function. + local first_window_index=$(__get_first_window_index) + tmux move-window -s "$session:$first_window_index" -t "$session:999" # Ensure correct pane splitting. __go_to_session @@ -207,7 +208,7 @@ initialize_session() { # to it here. # finalize_and_go_to_session() { - ! tmux kill-window -t "$session:99" 2>/dev/null + ! tmux kill-window -t "$session:999" 2>/dev/null if [[ "$(tmuxifier-current-session)" != "$session" ]]; then __go_to_session fi @@ -229,6 +230,16 @@ __expand_path() { echo $(eval echo "$@") } +__get_first_window_index() { + local index + index=$(tmux list-windows -t "$session:" -F "#{window_index}" 2>/dev/null) + if [ -n "$index" ]; then + echo "$index" | head -1 + else + echo "0" + fi +} + __go_to_session() { if [ -z "$TMUX" ]; then tmux -u attach-session -t "$session:"