mirror of
https://github.com/jimeh/tmuxifier.git
synced 2026-02-19 09:56:39 +00:00
Add __get_current_window_index internal helper function
This commit is contained in:
@@ -313,6 +313,15 @@ __get_first_window_index() {
|
||||
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() {
|
||||
if [ -z "$TMUX" ]; then
|
||||
tmuxifier-tmux -u attach-session -t "$session:"
|
||||
|
||||
48
test/lib/layout-helpers/__get_current_window_index.test.sh
Executable file
48
test/lib/layout-helpers/__get_current_window_index.test.sh
Executable 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()"
|
||||
Reference in New Issue
Block a user