mirror of
https://github.com/jimeh/tmuxifier.git
synced 2026-02-19 09:56:39 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3563c3d975 | |||
| 3bfbc50918 | |||
|
|
3a8a43ccdc | ||
|
|
a9a87992df | ||
| 5f4dd92d7f | |||
|
|
bdaa272ca5 | ||
| dce4fb3ad2 | |||
|
|
6f8773133d | ||
| 92d188f9f5 | |||
| 8d1751daea | |||
| dafa938923 | |||
| 595269dd6a |
@@ -4,6 +4,7 @@ env:
|
|||||||
- TMUX_VERSION="1.7"
|
- TMUX_VERSION="1.7"
|
||||||
- TMUX_VERSION="1.8"
|
- TMUX_VERSION="1.8"
|
||||||
- TMUX_VERSION="1.9a"
|
- TMUX_VERSION="1.9a"
|
||||||
|
- TMUX_VERSION="2.0"
|
||||||
before_install:
|
before_install:
|
||||||
- sudo apt-get update
|
- sudo apt-get update
|
||||||
- sudo apt-get install -y bc build-essential libevent-dev libncurses5-dev
|
- sudo apt-get install -y bc build-essential libevent-dev libncurses5-dev
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ example:
|
|||||||
- Setting the `TMUXIFIER_TMUX_ITERM_ATTACH` environment variable to `-CC`
|
- Setting the `TMUXIFIER_TMUX_ITERM_ATTACH` environment variable to `-CC`
|
||||||
before calling the `load-session` command.
|
before calling the `load-session` command.
|
||||||
|
|
||||||
[tmux integration]: https://code.google.com/p/iterm2/wiki/TmuxIntegration
|
[tmux integration]: https://gitlab.com/gnachman/iterm2/wikis/TmuxIntegration
|
||||||
|
|
||||||
## Inspiration
|
## Inspiration
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ new_window() {
|
|||||||
if [ -n "$2" ]; then local command=("$2"); fi
|
if [ -n "$2" ]; then local command=("$2"); fi
|
||||||
|
|
||||||
tmuxifier-tmux new-window -t "$session:" "${winarg[@]}" "${command[@]}"
|
tmuxifier-tmux new-window -t "$session:" "${winarg[@]}" "${command[@]}"
|
||||||
|
|
||||||
|
# Disable renaming if a window name was given.
|
||||||
|
if [ -n "$1" ]; then tmuxifier-tmux set-option -t "$1" allow-rename off; fi
|
||||||
|
|
||||||
window="$(__get_current_window_index)"
|
window="$(__get_current_window_index)"
|
||||||
__go_to_window_or_session_path
|
__go_to_window_or_session_path
|
||||||
}
|
}
|
||||||
@@ -185,31 +189,39 @@ load_window() {
|
|||||||
# - $2: (optional) Override default window name.
|
# - $2: (optional) Override default window name.
|
||||||
#
|
#
|
||||||
load_session() {
|
load_session() {
|
||||||
local file="$1"
|
local file
|
||||||
if [ ! -f "$file" ]; then
|
if [ "${1#*/}" = "$1" ]; then
|
||||||
file="$TMUXIFIER_LAYOUT_PATH/$1.session.sh"
|
# There's no slash in the path.
|
||||||
fi
|
if [ -f "$TMUXIFIER_LAYOUT_PATH/$1.session.sh" ] || [ ! -f "$1" ]; then
|
||||||
|
file="$TMUXIFIER_LAYOUT_PATH/$1.session.sh"
|
||||||
if [ -f "$file" ]; then
|
|
||||||
if [ $# -gt 1 ]; then
|
|
||||||
session="$2"
|
|
||||||
else
|
else
|
||||||
session="${1/%.session.sh}"
|
# bash's 'source' requires an slash in the filename to not use $PATH.
|
||||||
session="${session/%.sh}"
|
file="./$1"
|
||||||
fi
|
|
||||||
|
|
||||||
set_default_path=true
|
|
||||||
source "$file"
|
|
||||||
session=
|
|
||||||
|
|
||||||
# Reset `$session_root`.
|
|
||||||
if [[ "$session_root" != "$HOME" ]]; then
|
|
||||||
session_root="$HOME"
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
file="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [ -f "$file" ]; then
|
||||||
echo "\"$1\" session layout not found." >&2
|
echo "\"$1\" session layout not found." >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $# -gt 1 ]; then
|
||||||
|
session="$2"
|
||||||
|
else
|
||||||
|
session="${1/%.session.sh}"
|
||||||
|
session="${session/%.sh}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
set_default_path=true
|
||||||
|
source "$file"
|
||||||
|
session=
|
||||||
|
|
||||||
|
# Reset `$session_root`.
|
||||||
|
if [[ "$session_root" != "$HOME" ]]; then
|
||||||
|
session_root="$HOME"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create a new session, returning 0 on success, 1 on failure.
|
# Create a new session, returning 0 on success, 1 on failure.
|
||||||
@@ -261,6 +273,11 @@ initialize_session() {
|
|||||||
-d -s "$session" "${session_args[@]}"
|
-d -s "$session" "${session_args[@]}"
|
||||||
fi
|
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
|
# In order to ensure only specified windows are created, we move the
|
||||||
# default window to position 999, and later remove it with the
|
# default window to position 999, and later remove it with the
|
||||||
# `finalize_and_go_to_session` function.
|
# `finalize_and_go_to_session` function.
|
||||||
@@ -331,9 +348,19 @@ __go_to_session() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__go_to_window_or_session_path() {
|
__go_to_window_or_session_path() {
|
||||||
local window_or_session_root=${window_root-$session_root}
|
local target_path
|
||||||
if [ -n "$window_or_session_root" ]; then
|
|
||||||
run_cmd "cd \"$window_or_session_root\""
|
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"
|
run_cmd "clear"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,4 +13,4 @@ Outputs Tmuxifier version."
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "0.12.0"
|
echo "0.12.2"
|
||||||
|
|||||||
@@ -23,6 +23,17 @@ unset window_root
|
|||||||
restore run_cmd
|
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.
|
# When only $session_root is set, runs cd to $session_root path.
|
||||||
stub run_cmd
|
stub run_cmd
|
||||||
session_root="/usr"
|
session_root="/usr"
|
||||||
@@ -45,5 +56,33 @@ unset session_root
|
|||||||
restore run_cmd
|
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.
|
# End of tests.
|
||||||
assert_end "__go_to_window_or_session_path()"
|
assert_end "__go_to_window_or_session_path()"
|
||||||
|
|||||||
Reference in New Issue
Block a user