-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmuxattach
More file actions
executable file
·49 lines (41 loc) · 1.28 KB
/
Copy pathtmuxattach
File metadata and controls
executable file
·49 lines (41 loc) · 1.28 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
#!/bin/bash
# export TERM=xterm-256color
#
# Modified TMUX start script from:
# http://forums.gentoo.org/viewtopic-t-836006-start-0.html
#
# Store it to `~/bin/tmx` and issue `chmod +x`.
#
# use session "main" as default
if [[ -z "$1" ]]; then
sess_name="main"
else
sess_name="$1"
fi
# Only because I often issue `ls` to this script by accident
if [[ "$1" == "ls" ]]; then
tmux ls
exit
fi
sess_exists=`tmux ls | grep "^${sess_name}:" | wc -l`
sess_active=`tmux ls | grep "^${sess_name}" | grep "attached" | wc -l`
if [[ -z "$TMUX" ]]; then
# if sess does not yet exist make it
if [[ "$sess_exists" == "0" ]]; then
echo "Launching tmux base session $sess_name ..."
tmux new-session -s $sess_name
# if sess is inactive connect to it
elif [[ "$sess_active" == "0" ]]; then
tmux attach -t $sess_name
# else copy session and connect to it
else
session_id="${sess_name}_`date +%m%d%H%M%S`"
# Create a new session (without attaching it) and link to base session
# to share windows
tmux new-session -d -t $sess_name -s $session_id
# Attach to the new session
tmux attach-session -t $session_id
# When we detach from it, kill the session
tmux kill-session -t $session_id
fi
fi