forked from cowboy/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path60_tmux.sh
56 lines (52 loc) · 1.63 KB
/
60_tmux.sh
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
50
51
52
53
54
55
56
alias subl='reattach-to-user-namespace subl'
# tmux wrapper
# tm session-name [window-name]
# Names can be partial from the beginning and first match will connect.
# If no match is found a new session will be created.
# If there's a second argument, it will be used to attach directly to a
# window in the session, or to name the first window in a new session.
tm() {
local attach window
if [ -n $1 ]; then
attach=""
tmux has-session -t $1 > /dev/null
if [ $? -eq 0 ]; then
attach=$1
shift
else
for session in `tmux ls|awk -F ":" '{ print $1 }'`;do
if [[ $session =~ ^$1 ]]; then
echo "Matched session: $session"
attach=$session
shift
break
fi
done
fi
if [[ $attach != "" ]]; then
if [ $# -eq 1 ]; then
for win in `tmux list-windows -t $attach|sed -E 's/^[0-9]+: //'|sed -E 's/[*-].*//'`;do
if [[ $win =~ ^$1 ]]; then
echo "Matched window: $window"
window=$win
break
fi
done
tmux attach -t $attach:$window
else
tmux attach -t $attach
fi
else
if [ $# -gt 1 ]; then
attach=$1
shift
tmux new -s $attach -n $1
else
echo "Attempting to create $1"
tmux new -s $1
fi
fi
else
tmux new
fi
}