-
Notifications
You must be signed in to change notification settings - Fork 1
/
tp
executable file
·83 lines (69 loc) · 1.68 KB
/
tp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/sh
DIR=`dirname $0`
CODE_DIR="$HOME/code"
CODE_TMUXINATOR_FILE=".tmuxinator.yml"
if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "help" ]; then
cat <<EOF
$ tp PROJECT
Start a tmux(inator) project.
Add a new one with: mktmuxinator
Parameters:
\$1: name of the project to be started
Commands:
print_completions: print list of available projects
Examples:
$ tp
$ tp main
$ tp print_completions
EOF
exit
fi
command -v tmuxinator >/dev/null || { echo "tmuxinator is not installed" 1>&2; exit 127; }
PROJECT=$1
[ -z "$1" ] && PROJECT=main
print_completions() {
cat <<EOF
$(fd -t f -e yml --glob "*.yml" $DIR/tmuxinator | rev | cut -d. -f2 | cut -d/ -f1 | rev)
$(fd -H -t f -e yml "$CODE_TMUXINATOR_FILE" $CODE_DIR | rev | cut -d/ -f2 | rev)
EOF
}
if [ "$PROJECT" = "print_completions" ]; then
print_completions
exit 0
fi
if ! print_completions | grep "$PROJECT" >/dev/null; then
echo "Invalid project chosen. Must be one of:\n"
print_completions
exit 1
fi
is_inside_tmux() {
[ "$TMUX_PANE" = "%0" ]
}
if tmux list-sessions 2>/dev/null | cut -d: -f1 | grep "^$PROJECT$" >/dev/null; then
if is_inside_tmux; then
tmux switch-client -t "$PROJECT"
else
tmux -u attach -t "$PROJECT"
fi
exit 0
fi
is_config() {
if [ -f "$DIR/tmuxinator/$PROJECT.yml" ]; then
true
else
false
fi
}
run_config() {
tmuxinator start $PROJECT -p $DIR/tmuxinator/$PROJECT.yml
}
run_code_project() {
tmuxinator start $PROJECT -p "$CODE_DIR/$PROJECT/$CODE_TMUXINATOR_FILE"
}
# Apply non-global tmux configuration
( sleep 4s && tmux source-file -t "$PROJECT" "$HOME/.config/tmux/tmux.conf" ) >/dev/null 2>&1 &
if is_config; then
run_config
else
run_code_project
fi