-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathtmux_new_session.sh
More file actions
executable file
·49 lines (38 loc) · 1.09 KB
/
tmux_new_session.sh
File metadata and controls
executable file
·49 lines (38 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# global variable
SESSION_NAME="$1"
SESSION_PATH="$2"
source "$CURRENT_DIR/helpers.sh"
default_sessionist_use_pane_directory=""
tmux_option_sessionist_use_pane_directory="@sessionist-use-pane-directory"
session_name_not_provided() {
[ -z "$SESSION_NAME" ]
}
session_exists() {
tmux has-session -t "$SESSION_NAME" > /dev/null 2>&1
}
switch_to_session() {
local session_name="$1"
tmux switch-client -t "$session_name"
}
create_new_tmux_session() {
local use_pane_directory=$(get_tmux_option "$tmux_option_sessionist_use_pane_directory" "$default_sessionist_use_pane_directory")
local tmux_extra_args=""
if [ "$use_pane_directory" = "true" ] ;then
tmux_extra_args=" -c $SESSION_PATH "
fi
if session_name_not_provided; then
exit 0
elif session_exists; then
switch_to_session "$SESSION_NAME"
display_message "Switched to existing session ${SESSION_NAME}" "1000"
else
TMUX="" tmux new $tmux_extra_args -d -s "$SESSION_NAME"
switch_to_session "$SESSION_NAME"
fi
}
main() {
create_new_tmux_session
}
main