mirror of
https://github.com/jimeh/tmuxifier.git
synced 2026-02-19 01:46:40 +00:00
Set $window var based on currently active window
Previously $window was only set by the new_window() helper when it was
passed a name argument. This caused weird behavior cause if it was
called without a name it would simply attempt to recreate the same
window and fail. That was until @blueyed's fix in 2249cf8.
However, the $window var still wasn't being set correctly, leaving
split_v(), split_h() and other helpers to operate on the wrong
window. This is no longer an issue as $window is always set to the index
of the currently active window at the end of new_window() and
select_window().
This commit is contained in:
@@ -18,13 +18,11 @@ tmux() {
|
||||
# - $2: (optional) Shell command to execute when window is created.
|
||||
#
|
||||
new_window() {
|
||||
if [ -n "$1" ]; then
|
||||
window="$1"
|
||||
local winarg=(-n "$window")
|
||||
fi
|
||||
if [ -n "$1" ]; then local winarg=(-n "$1"); fi
|
||||
if [ -n "$2" ]; then local command=("$2"); fi
|
||||
|
||||
tmuxifier-tmux new-window -t "$session:" "${winarg[@]}" "${command[@]}"
|
||||
window="$(__get_current_window_index)"
|
||||
__go_to_window_or_session_path
|
||||
}
|
||||
|
||||
@@ -91,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.
|
||||
|
||||
@@ -39,9 +39,20 @@ 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