-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmux_sessionize
More file actions
executable file
·48 lines (40 loc) · 1.07 KB
/
tmux_sessionize
File metadata and controls
executable file
·48 lines (40 loc) · 1.07 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
#!/usr/bin/env bash
switch_to() {
if [[ -z $TMUX ]]; then
tmux attach-session -t $1
else
tmux switch-client -t $1
fi
}
has_session() {
tmux list-sessions | grep -q "^$1:"
}
hydrate() {
if [ -f $2/.tmux-sessionizer ]; then
tmux send-keys -t $1 "source $2/.tmux-sessionizer" c-M
elif [ -f $HOME/.tmux-sessionizer ]; then
tmux send-keys -t $1 "source $HOME/.tmux-sessionizer" c-M
fi
}
if [[ $# -eq 1 ]]; then
selected=$1
else
# If someone wants to make this extensible, i'll accept
# PR
selected=$(find ~/learning ~/personal ~/learning ~/.config ~/DEV -mindepth 1 -maxdepth 1 -type d | fzf)
fi
if [[ -z $selected ]]; then
exit 0
fi
selected_name=$(basename "$selected" | tr . _)
tmux_running=$(pgrep tmux)
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then
tmux new-session -s $selected_name -c $selected
hydrate $selected_name $selected
exit 0
fi
if ! has_session $selected_name; then
tmux new-session -ds $selected_name -c $selected
hydrate $selected_name $selected
fi
switch_to $selected_name