-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathide-tmux
More file actions
executable file
·69 lines (57 loc) · 1.47 KB
/
ide-tmux
File metadata and controls
executable file
·69 lines (57 loc) · 1.47 KB
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
64
65
66
67
68
69
#!/usr/bin/env bash
set -euo pipefail
root_folder=${PWD}
main_file=""
session_name="default"
with_test_window=false
info() {
printf 'Usage: %s [-n NAME] [-t] [-d FOLDER] [-f FILE] [-h]\n' "$0"
printf '\t-n\tNAME for the tmux session\n'
printf '\t-t\tAdd an extra test window\n'
printf '\t-d\tSet the FOLDER where the project is\n'
printf '\t-f\tOpen FILE in vim\n'
printf '\t-h\tDisplay this help\n'
}
while getopts ':d:f:thn:' o; do
case "$o" in
d) root_folder=$OPTARG ;;
f) main_file=$OPTARG ;;
n) session_name=$OPTARG ;;
t) with_test_window=true ;;
h)
info
exit 0
;;
*)
info
exit 1
;;
esac
done
command -v tmux >/dev/null 2>&1 || {
echo 'tmux is required but was not found in PATH.' >&2
exit 1
}
[[ -d "$root_folder" ]] || {
echo "Project folder not found: $root_folder" >&2
exit 1
}
if tmux has-session -t "$session_name" 2>/dev/null; then
exec tmux attach -t "$session_name"
fi
cd "$root_folder"
vim_cmd='vim'
if [[ -n "$main_file" ]]; then
vim_cmd="vim '$main_file'"
fi
tmux new-session -s "$session_name" -d "$vim_cmd"
tmux split-window -h -p 25 'htop'
tmux split-window -v -p 50
tmux split-window -v
if $with_test_window; then
tmux new-window -t "$session_name":1 -n test
tmux split-window -h 'btm'
fi
tmux select-window -t "$session_name":0
tmux select-pane -t 0
exec tmux attach -t "$session_name"