-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux-project
executable file
·40 lines (33 loc) · 919 Bytes
/
tmux-project
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
#! /usr/bin/env bash
fzf_dir=$(
fd . \
--base-directory ~/Projects \
--maxdepth 2 \
--type d \
--exclude .git |
fzf \
--ansi \
--margin=20% \
--preview-window=50% \
--preview '~/scripts/preview.sh ~/Projects/{}'
)
if [ -n "$fzf_dir" ]; then
dir="$HOME/Projects/$fzf_dir"
else
exit 1
fi
# Create a detached session with Session name
session="Project"
SESSIONEXISTS=$(tmux list-sessions | grep $session)
# Only create tmux session if it doesn't already exist
if [ "$SESSIONEXISTS" = "" ]; then
tmux new-session -d -s $session
tmux rename-window -t "$session:1" 'Main'
tmux send-keys -t "$session:1" "cd '$dir' && clear" C-m
tmux send-keys -t "$session:1" "nvim" C-m
tmux new-window -t "$session:2" -n "Terminal"
tmux send-keys -t "$session:2" "cd '$dir' && clear" C-m
tmux attach-session -t "$session:1"
else
tmux attach-session -t "$session:1"
fi