mirror of
https://github.com/jimeh/tmuxifier.git
synced 2026-02-19 01:46:40 +00:00
Merge pull request #50 from jimeh/fix-new_window-active-window-tracking
Fix new window active window tracking
This commit is contained in:
@@ -18,11 +18,11 @@ tmux() {
|
||||
# - $2: (optional) Shell command to execute when window is created.
|
||||
#
|
||||
new_window() {
|
||||
if [ -n "$1" ]; then window="$1"; fi
|
||||
if [ -n "$1" ]; then local winarg=(-n "$1"); fi
|
||||
if [ -n "$2" ]; then local command=("$2"); fi
|
||||
if [ -n "$window" ]; then local winarg=(-n "$window"); fi
|
||||
|
||||
tmuxifier-tmux new-window -t "$session:" "${winarg[@]}" "${command[@]}"
|
||||
window="$(__get_current_window_index)"
|
||||
__go_to_window_or_session_path
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ clock() {
|
||||
#
|
||||
select_window() {
|
||||
tmuxifier-tmux select-window -t "$session:$1"
|
||||
window="$(__get_current_window_index)"
|
||||
}
|
||||
|
||||
# Select a specific pane in the current window.
|
||||
@@ -311,6 +312,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()"
|
||||
@@ -34,14 +34,26 @@ stub __go_to_window_or_session_path
|
||||
new_window "foobardoo" "touch /tmp/tmuxifier-new_window-test; bash"
|
||||
assert "test-socket-window-count" "2"
|
||||
assert "test-socket-window-count foobardoo" "1"
|
||||
sleep 0.1 # attempt to avoid timing issue causing flicker
|
||||
assert_raises 'test -f "/tmp/tmuxifier-new_window-test"' 0
|
||||
restore __go_to_window_or_session_path
|
||||
kill-test-session
|
||||
rm "/tmp/tmuxifier-new_window-test" &> /dev/null
|
||||
|
||||
|
||||
# Tear down.
|
||||
kill-test-server
|
||||
# When called ensure it sets the $window variable to the index of the newly
|
||||
# created window.
|
||||
unset window
|
||||
create-test-session
|
||||
stub __go_to_window_or_session_path
|
||||
new_window "foo"
|
||||
assert "echo $window" "1"
|
||||
new_window
|
||||
assert "echo $window" "2"
|
||||
new_window "bar"
|
||||
assert "echo $window" "3"
|
||||
restore __go_to_window_or_session_path
|
||||
kill-test-session
|
||||
unset window
|
||||
|
||||
# End of tests.
|
||||
assert_end "new_window()"
|
||||
|
||||
55
test/lib/layout-helpers/select_window.test.sh
Executable file
55
test/lib/layout-helpers/select_window.test.sh
Executable file
@@ -0,0 +1,55 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../../test-helper.sh"
|
||||
source "${root}/lib/layout-helpers.sh"
|
||||
|
||||
#
|
||||
# select_window() tests.
|
||||
#
|
||||
|
||||
window_list() {
|
||||
test-socket-tmux list-windows -t "$session:" \
|
||||
-F "#{window_active}:#{window_index}" 2>/dev/null
|
||||
}
|
||||
|
||||
# Selects given window when passed a window index
|
||||
create-test-session
|
||||
test-socket-tmux new-window -t "$session:1"
|
||||
test-socket-tmux new-window -t "$session:2"
|
||||
select_window 0
|
||||
assert "window_list | grep '^1:'" "1:0"
|
||||
select_window 1
|
||||
assert "window_list | grep '^1:'" "1:1"
|
||||
select_window 2
|
||||
assert "window_list | grep '^1:'" "1:2"
|
||||
kill-test-session
|
||||
|
||||
# Selects given window when passed a window name
|
||||
create-test-session
|
||||
test-socket-tmux new-window -t "$session:1" -n "foo"
|
||||
test-socket-tmux new-window -t "$session:2" -n "bar"
|
||||
select_window foo
|
||||
assert "window_list | grep '^1:'" "1:1"
|
||||
select_window bar
|
||||
assert "window_list | grep '^1:'" "1:2"
|
||||
kill-test-session
|
||||
|
||||
|
||||
# When called ensure it sets the $window variable to the index of the newly
|
||||
# created window.
|
||||
unset window
|
||||
create-test-session
|
||||
test-socket-tmux new-window -t "$session:1" -n "foo"
|
||||
test-socket-tmux new-window -t "$session:2" -n "bar"
|
||||
select_window "foo"
|
||||
assert "echo $window" "1"
|
||||
select_window "bar"
|
||||
assert "echo $window" "2"
|
||||
select_window 1
|
||||
assert "echo $window" "1"
|
||||
select_window 2
|
||||
assert "echo $window" "2"
|
||||
kill-test-session
|
||||
unset window
|
||||
|
||||
# End of tests.
|
||||
assert_end "select_window()"
|
||||
Reference in New Issue
Block a user