-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtx.sh
executable file
·41 lines (35 loc) · 881 Bytes
/
tx.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
#!/bin/bash
#
# Helper for tmux.
#
set_ssh_env()
{
tmux set-environment -g SSH_AUTH_SOCK $SSH_AUTH_SOCK
tmux set-environment -g SSH_CLIENT "$SSH_CLIENT"
tmux set-environment -g SSH_CONNECTION "$SSH_CONNECTION"
}
NAME=$1
CFG=""
if [[ $NAME != "" ]]; then
EXISTS=`tmux ls 2>/dev/null | cut -d: -f1 | grep $NAME`
if [[ `uname` == "Darwin" ]]; then
CFG="-f $HOME/.tmux_osx.conf"
fi
if [ "x$EXISTS" = "x" ]; then
tmux $CFG new-session -d -s $NAME
fi
#set_ssh_env
tmux attach-session -t $NAME
else
sessions=$(tmux ls 2>/dev/null)
num=$(tmux ls 2>/dev/null | wc -l)
if [ $num -eq 1 ]; then
#set_ssh_env
tmux attach-session -t $(echo $sessions | cut -d: -f1)
else
echo "Usage: tx session-name"
echo ""
echo "Available sessions:"
tmux ls 2>/dev/null
fi
fi