-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmuxa
executable file
·63 lines (52 loc) · 1.52 KB
/
tmuxa
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
57
58
59
60
61
62
63
#!/bin/bash
# Convenience script for finding a tmux session by name and attaching to it.
# The session will be created if it doesn't exist, and a predefined layout will
# be applied. An initial working directory can be specified as the second argument.
#
# ex.
# tmuxa mysession --dir=~/projects/myproject
if [ $# -lt 1 ]; then
echo "usage: tmuxa <session-name> [--dir=<dir>] [--no-layout] [--cmd=<cmd>]"
exit 1
fi
# Default values
session_name="$1"
no_layout=false
dir="$HOME"
cmd=""
# Loop through the arguments to automatically assign variables
for arg in "$@"; do
case "$arg" in
--dir=*)
dir="${arg#--dir=}"
;;
--no-layout)
no_layout=true
;;
--cmd=*)
cmd="${arg#--cmd=}"
;;
esac
done
cd $dir
p2s="tmux-pane-view --pane-to-session"
if [ -n "$cmd" ]; then
p2s="$p2s --cmd=\"$cmd\""
fi
# If the session doesn't exist, create it and set up the layout
if ! tmux has-session -t "$1" 2>/dev/null; then
if [ "$no_layout" = false ]; then
tmux new-session -d -s "$1" $p2s \; \
split-window -v -l "90%" $p2s \; \
select-pane -t 0 \; \
split-window -h $p2s \; \
split-window -h $p2s \; \
select-pane -t 3 \; \
setw window-active-style bg=black
else
tmux new-session -d -s "$1" "$p2s"
fi
sessions=$(tmux list-panes -a -F '#{pane_id} #{session_name}' | grep _child | awk '{print $2}')
fi
# Otherwise, attach to the session
tmux attach -t "$session_name"