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.
This commit is contained in:
2015-07-25 13:24:02 +01:00
parent b801aade99
commit 595269dd6a
2 changed files with 57 additions and 3 deletions

View File

@@ -261,6 +261,11 @@ initialize_session() {
-d -s "$session" "${session_args[@]}"
fi
if $set_default_path && [[ "$session_root" != "$HOME" ]]; then
tmuxifier-tmux setenv -t "$session:" \
TMUXIFIER_SESSION_ROOT "$session_root"
fi
# In order to ensure only specified windows are created, we move the
# default window to position 999, and later remove it with the
# `finalize_and_go_to_session` function.
@@ -331,9 +336,19 @@ __go_to_session() {
}
__go_to_window_or_session_path() {
local window_or_session_root=${window_root-$session_root}
if [ -n "$window_or_session_root" ]; then
run_cmd "cd \"$window_or_session_root\""
local target_path
if [ -n "$window_root" ]; then
target_path="$window_root"
elif [ -n "$TMUXIFIER_SESSION_ROOT" ]; then
target_path="$TMUXIFIER_SESSION_ROOT"
elif [ -n "$session_root" ]; then
target_path="$session_root"
fi
# local window_or_session_root=${window_root-$session_root}
if [ -n "$target_path" ]; then
run_cmd "cd \"$target_path\""
run_cmd "clear"
fi
}

View File

@@ -23,6 +23,17 @@ unset window_root
restore run_cmd
# When only $TMUXIFIER_SESSION_ROOT is set, runs cd to $TMUXIFIER_SESSION_ROOT
# path.
stub run_cmd
TMUXIFIER_SESSION_ROOT="/opt"
__go_to_window_or_session_path
assert 'stub_called_with_times run_cmd cd \"/opt\"' "1"
assert 'stub_called_with_times run_cmd clear' "1"
unset TMUXIFIER_SESSION_ROOT
restore run_cmd
# When only $session_root is set, runs cd to $session_root path.
stub run_cmd
session_root="/usr"
@@ -45,5 +56,33 @@ unset session_root
restore run_cmd
# When $TMUXIFIER_SESSION_ROOT and $session_root are set, runs cd to
# $TMUXIFIER_SESSION_ROOT path.
stub run_cmd
TMUXIFIER_SESSION_ROOT="/opt"
session_root="/usr"
__go_to_window_or_session_path
assert 'stub_called_with_times run_cmd cd \"/opt\"' "1"
assert 'stub_called_with_times run_cmd clear' "1"
unset TMUXIFIER_SESSION_ROOT
unset session_root
restore run_cmd
# When $window_root, $TMUXIFIER_SESSION_ROOT, and $session_root are set, runs
# cd to $window_root path.
stub run_cmd
window_root="/tmp"
TMUXIFIER_SESSION_ROOT="/opt"
session_root="/usr"
__go_to_window_or_session_path
assert 'stub_called_with_times run_cmd cd \"/tmp\"' "1"
assert 'stub_called_with_times run_cmd clear' "1"
unset window_root
unset TMUXIFIER_SESSION_ROOT
unset session_root
restore run_cmd
# End of tests.
assert_end "__go_to_window_or_session_path()"