Skip to content

Commit 595269d

Browse files
committed
Make load-window within a session adhere to session_root setting
This should fix #61. Previously when you manually ran `tmuxifier load-window` from within a session created by Tmuxifier, the `session_root` path set in the session was ignored, and the new window would be cd'd to `$HOME` unless the window configuration had `window_root` set.
1 parent b801aad commit 595269d

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

lib/layout-helpers.sh

+18-3
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ initialize_session() {
261261
-d -s "$session" "${session_args[@]}"
262262
fi
263263

264+
if $set_default_path && [[ "$session_root" != "$HOME" ]]; then
265+
tmuxifier-tmux setenv -t "$session:" \
266+
TMUXIFIER_SESSION_ROOT "$session_root"
267+
fi
268+
264269
# In order to ensure only specified windows are created, we move the
265270
# default window to position 999, and later remove it with the
266271
# `finalize_and_go_to_session` function.
@@ -331,9 +336,19 @@ __go_to_session() {
331336
}
332337

333338
__go_to_window_or_session_path() {
334-
local window_or_session_root=${window_root-$session_root}
335-
if [ -n "$window_or_session_root" ]; then
336-
run_cmd "cd \"$window_or_session_root\""
339+
local target_path
340+
341+
if [ -n "$window_root" ]; then
342+
target_path="$window_root"
343+
elif [ -n "$TMUXIFIER_SESSION_ROOT" ]; then
344+
target_path="$TMUXIFIER_SESSION_ROOT"
345+
elif [ -n "$session_root" ]; then
346+
target_path="$session_root"
347+
fi
348+
349+
# local window_or_session_root=${window_root-$session_root}
350+
if [ -n "$target_path" ]; then
351+
run_cmd "cd \"$target_path\""
337352
run_cmd "clear"
338353
fi
339354
}

test/lib/layout-helpers/__go_to_window_or_session_path.test.sh

+39
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ unset window_root
2323
restore run_cmd
2424

2525

26+
# When only $TMUXIFIER_SESSION_ROOT is set, runs cd to $TMUXIFIER_SESSION_ROOT
27+
# path.
28+
stub run_cmd
29+
TMUXIFIER_SESSION_ROOT="/opt"
30+
__go_to_window_or_session_path
31+
assert 'stub_called_with_times run_cmd cd \"/opt\"' "1"
32+
assert 'stub_called_with_times run_cmd clear' "1"
33+
unset TMUXIFIER_SESSION_ROOT
34+
restore run_cmd
35+
36+
2637
# When only $session_root is set, runs cd to $session_root path.
2738
stub run_cmd
2839
session_root="/usr"
@@ -45,5 +56,33 @@ unset session_root
4556
restore run_cmd
4657

4758

59+
# When $TMUXIFIER_SESSION_ROOT and $session_root are set, runs cd to
60+
# $TMUXIFIER_SESSION_ROOT path.
61+
stub run_cmd
62+
TMUXIFIER_SESSION_ROOT="/opt"
63+
session_root="/usr"
64+
__go_to_window_or_session_path
65+
assert 'stub_called_with_times run_cmd cd \"/opt\"' "1"
66+
assert 'stub_called_with_times run_cmd clear' "1"
67+
unset TMUXIFIER_SESSION_ROOT
68+
unset session_root
69+
restore run_cmd
70+
71+
72+
# When $window_root, $TMUXIFIER_SESSION_ROOT, and $session_root are set, runs
73+
# cd to $window_root path.
74+
stub run_cmd
75+
window_root="/tmp"
76+
TMUXIFIER_SESSION_ROOT="/opt"
77+
session_root="/usr"
78+
__go_to_window_or_session_path
79+
assert 'stub_called_with_times run_cmd cd \"/tmp\"' "1"
80+
assert 'stub_called_with_times run_cmd clear' "1"
81+
unset window_root
82+
unset TMUXIFIER_SESSION_ROOT
83+
unset session_root
84+
restore run_cmd
85+
86+
4887
# End of tests.
4988
assert_end "__go_to_window_or_session_path()"

0 commit comments

Comments
 (0)