-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-tmux.sh
executable file
·60 lines (55 loc) · 2 KB
/
new-tmux.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/zsh
SESSIONNAME=$1
if [[ $# == 2 ]]; then
lang=$2
fi
if [[ $# != 0 && -d "$SESSIONNAME" ]]; then
printf '%s%s\n' "Initializing session: " "$SESSIONNAME"
tmux has-session -t $SESSIONNAME &> /dev/null
if [ $? != 0 ]; then
tmux new-session -s $SESSIONNAME -n script -d
# Create 3 panes. Each will be in the project's dir.
# First pane will have vim and nerdtree open
tmux send-keys -t $SESSIONNAME "cd $SESSIONNAME" C-m
if [ ${lang+x} ]; then
echo "Installing pipenv..."
sleep 2
tmux send-keys -t $SESSIONNAME "pipenv install --dev --python 3.6" C-m
# Would be nice if we could user tmux wait-for here. But pipenv install is async
# The following hack basically does the same thing
echo "Waiting for pipenv install..."
sleep 15
tmux capture-pane -t $SESSIONNAME:0
old_buffer=""
new_buffer=$(tmux show-buffer)
while [[ "$old_buffer" != "$new_buffer" ]] ; do
sleep 15
diff <(echo "$old_buffer" ) <(echo "$new_buffer")
old_buffer=$new_buffer
tmux capture-pane -t $SESSIONNAME:0
new_buffer=$(tmux show-buffer)
done
# On with the show
tmux send-keys -t $SESSIONNAME "pipenv shell" C-m
sleep 2
tmux send-keys -t $SESSIONNAME "pip install pylama" C-m
fi
tmux send-keys -t $SESSIONNAME "vim" C-m
tmux send-keys -t $SESSIONNAME ":NERDTree" C-m
tmux split-window -h
tmux resize-pane -R -t 0 20 C-m
tmux send-keys -t $SESSIONNAME "cd $SESSIONNAME" C-m
if [ ${lang+x} ]; then
tmux send-keys -t $SESSIONNAME "pipenv shell" C-m
fi
tmux split-window -v
tmux send-keys -t $SESSIONNAME "cd $SESSIONNAME" C-m
if [ ${lang+x} ]; then
tmux send-keys -t $SESSIONNAME "pipenv shell" C-m
fi
tmux select-pane -t 0
fi
tmux attach -t $SESSIONNAME
else
printf '%s\n' "Need pass the name of a folder 'new-tmux.sh <folder-name>'"
fi