-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathx
executable file
·45 lines (35 loc) · 1.04 KB
/
x
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
#! /bin/sh
DEFAULT_SESSION=main
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ]; then
printf "$ t [session]
Attach to a tmux session or create it if it doesn't exist.
If no parameter given attach to the default session ($DEFAULT_SESSION).
Parameters:
[\$1]: session to attach to
[\$2]: command to run (only for new sessions), to be used for scripting
Example:
$ t main
$ t code vim
"; exit
fi
command -v tmux >/dev/null || { echo "tmux is not installed"; exit 1; }
SESSION="$1"
if [ -z "$SESSION" ]; then
SESSION="$DEFAULT_SESSION"
fi
CMD="$2"
CD="" # depending on session name set a default path to cd to
case "$SESSION" in
code|dev|js|ts) CD="-c $HOME/code";;
uni) CD="-c $HOME/projects/uni";;
esac
if tmux list-sessions 2>/dev/null | cut -d: -f1 | grep "^$SESSION$" >/dev/null; then
tmux -u attach -t "$SESSION"
else
if [ -n "$CMD" ]; then
tmux -u new -s "$SESSION" $CD \; send-keys "$CMD" 'Enter'
else
tmux -u new -s "$SESSION" $CD
fi
fi
# -u for UTF-8 even if the correct ENV variables are missing