mirror of
https://github.com/jimeh/tmuxifier.git
synced 2026-02-19 09:56:39 +00:00
Clean up structure of initialize_session helper function
This commit is contained in:
@@ -232,40 +232,40 @@ initialize_session() {
|
|||||||
tmuxifier-tmux start-server
|
tmuxifier-tmux start-server
|
||||||
|
|
||||||
# Check if the named session already exists.
|
# Check if the named session already exists.
|
||||||
if ! tmuxifier-tmux has-session -t "$session:" 2>/dev/null; then
|
if tmuxifier-tmux has-session -t "$session:" 2>/dev/null; then
|
||||||
if [ "$(tmuxifier-tmux-version "1.9")" == "<" ]; then
|
return 1
|
||||||
# Tmux 1.8 and earlier.
|
fi
|
||||||
|
|
||||||
# Create the new session.
|
# Tmux 1.8 and earlier.
|
||||||
env TMUX="" tmuxifier-tmux new-session -d -s "$session"
|
if [ "$(tmuxifier-tmux-version "1.9")" == "<" ]; then
|
||||||
|
# Create the new session.
|
||||||
|
env TMUX="" tmuxifier-tmux new-session -d -s "$session"
|
||||||
|
|
||||||
# Set default-path for session
|
# Set default-path for session
|
||||||
if [ -n "$session_root" ] && [ -d "$session_root" ]; then
|
if [ -n "$session_root" ] && [ -d "$session_root" ]; then
|
||||||
cd "$session_root"
|
cd "$session_root"
|
||||||
|
|
||||||
$set_default_path && tmuxifier-tmux \
|
$set_default_path && tmuxifier-tmux \
|
||||||
set-option -t "$session:" \
|
set-option -t "$session:" \
|
||||||
default-path "$session_root" 1>/dev/null
|
default-path "$session_root" 1>/dev/null
|
||||||
fi
|
|
||||||
else
|
|
||||||
# Tmux 1.9 and later.
|
|
||||||
if $set_default_path; then local session_args=(-c "$session_root"); fi
|
|
||||||
env TMUX="" tmuxifier-tmux new-session \
|
|
||||||
-d -s "$session" "${session_args[@]}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# In order to ensure only specified windows are created, we move the
|
# Tmux 1.9 and later.
|
||||||
# default window to position 999, and later remove it with the
|
else
|
||||||
# `finalize_and_go_to_session` function.
|
if $set_default_path; then
|
||||||
local first_window_index=$(__get_first_window_index)
|
local session_args=(-c "$session_root")
|
||||||
tmuxifier-tmux move-window \
|
fi
|
||||||
-s "$session:$first_window_index" -t "$session:999"
|
|
||||||
|
|
||||||
# Session created, return ok exit status.
|
env TMUX="" tmuxifier-tmux new-session \
|
||||||
return 0
|
-d -s "$session" "${session_args[@]}"
|
||||||
fi
|
fi
|
||||||
# Session already existed, return error exit status.
|
|
||||||
return 1
|
# 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.
|
||||||
|
local first_window_index=$(__get_first_window_index)
|
||||||
|
tmuxifier-tmux move-window \
|
||||||
|
-s "$session:$first_window_index" -t "$session:999"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Finalize session creation and then switch to it if needed.
|
# Finalize session creation and then switch to it if needed.
|
||||||
|
|||||||
Reference in New Issue
Block a user