-
Notifications
You must be signed in to change notification settings - Fork 39
/
tmx
executable file
·54 lines (47 loc) · 1.75 KB
/
tmx
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
#!/bin/bash
#
# Modified TMUX start script from:
# http://forums.gentoo.org/viewtopic-t-836006-start-0.html
#
# Works because bash automatically trims by assigning to variables and by
# passing arguments
trim() { echo $1; }
if [[ -z "$1" ]]; then
echo "Specify session name as the first argument"
exit
fi
base_session="$1"
# This actually works without the trim() on all systems except OSX
tmux_nb=$(trim `tmux ls | grep "^$base_session" | wc -l`)
# path to startup script (session name passed as argument)
startup_script="$HOME/Scripts/tmux-startup.sh"
if [[ "$tmux_nb" == "0" ]]; then
if [[ -x "$startup_script" ]]; then
echo "Launching startup file '$startup_script $base_session'"
"$startup_script" $base_session
else
echo "Launching tmux base session $base_session"
tmux new-session -s $base_session
fi
else
# Make sure we are not already in a tmux session
if [[ -z "$TMUX" ]]; then
# Kill defunct sessions first
old_sessions=$(tmux ls 2>/dev/null | egrep "^[0-9]{14}.*[0-9]+\)$" | cut -f 1 -d:)
for old_session_id in $old_sessions; do
tmux kill-session -t $old_session_id
done
echo "Launching copy of base session $base_session ..."
# Session is is date and time to prevent conflict
session_id=`date +%Y%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 $base_session -s $session_id
# select window to connect to
tmux select-window -t $session_id:1
# 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