Add __get_current_window_index internal helper function

This commit is contained in:
2014-08-29 22:28:25 +01:00
parent 2249cf8d1b
commit 0ae0bc84e3
2 changed files with 57 additions and 0 deletions

View File

@@ -313,6 +313,15 @@ __get_first_window_index() {
fi fi
} }
__get_current_window_index() {
local lookup=$(tmuxifier-tmux list-windows -t "$session:" \
-F "#{window_active}:#{window_index}" 2>/dev/null | grep "^1:")
if [ -n "$lookup" ]; then
echo "${lookup/1:}"
fi
}
__go_to_session() { __go_to_session() {
if [ -z "$TMUX" ]; then if [ -z "$TMUX" ]; then
tmuxifier-tmux -u attach-session -t "$session:" tmuxifier-tmux -u attach-session -t "$session:"

View File

@@ -0,0 +1,48 @@
#! /usr/bin/env bash
source "../../test-helper.sh"
source "${root}/lib/layout-helpers.sh"
#
# __get_current_window_index() tests.
#
# When current window is the first and only window.
create-test-session
assert "__get_current_window_index" "0"
kill-test-session
# When creating a second window.
create-test-session
test-socket-tmux new-window -t "$session:1"
assert "__get_current_window_index" "1"
kill-test-session
# When creating a second window and then switching back to the first window.
create-test-session
test-socket-tmux new-window -t "$session:1"
test-socket-tmux select-window -t "$session:0"
assert "__get_current_window_index" "0"
kill-test-session
# When creating multiples windows and switching between them randomly.
create-test-session
assert "__get_current_window_index" "0"
test-socket-tmux new-window -t "$session:1"
assert "__get_current_window_index" "1"
test-socket-tmux new-window -t "$session:2"
assert "__get_current_window_index" "2"
test-socket-tmux new-window -t "$session:3"
assert "__get_current_window_index" "3"
test-socket-tmux select-window -t "$session:1"
assert "__get_current_window_index" "1"
test-socket-tmux select-window -t "$session:0"
assert "__get_current_window_index" "0"
test-socket-tmux select-window -t "$session:3"
assert "__get_current_window_index" "3"
test-socket-tmux select-window -t "$session:2"
assert "__get_current_window_index" "2"
kill-test-session
# End of tests.
assert_end "__get_current_window_index()"