blob: 419484a544f97935bcf0118102b97e4adfe8aaf5 (
plain)
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
|
#!/bin/sh
if [[ $# -eq 1 ]]; then
selected=$1
else
selected=$(fd '^.git$' -a --hidden --no-ignore --type d ./programming --exec dirname | grep -v "thirdparties" | fzf)
fi
if [[ -z $selected ]]; then
exit 1
fi
selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)
create_session() {
tmux new-session -d -s $selected_name -n nvim
tmux send-keys -t "$selected_name:1" "cd $selected && clear && nvim ." Enter
# Create second window (shell)
tmux new-window -t $selected_name -n shell
tmux send-keys -t "$selected_name:2" "cd $selected && clear" Enter
# Create third window (git)
tmux new-window -t $selected_name -n git
tmux send-keys -t "$selected_name:3" "cd $selected && clear && lazygit" Enter
}
# If not in tmux, create and attach
if [[ -z $TMUX ]]; then
create_session
tmux attach-session -t $selected_name
else
# If in tmux, create if needed and switch
if ! tmux has-session -t=$selected_name 2>/dev/null; then
create_session
fi
tmux switch-client -t $selected_name
fi
|