| 1 | #!/bin/env bash |
| 2 | |
| 3 | if [[ $# -eq 1 ]]; then |
| 4 | selected=$1; |
| 5 | else |
| 6 | selected=$(find ~/code/dev ~/code/repos ~/code/rust -mindepth 1 -maxdepth 1 -type d | fzf); |
| 7 | fi |
| 8 | |
| 9 | if [[ -z $selected ]]; then |
| 10 | exit 0 |
| 11 | fi |
| 12 | |
| 13 | selected_name=$(basename "$selected" | tr . _) |
| 14 | tmux_running=$(pgrep tmux) |
| 15 | |
| 16 | if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then |
| 17 | tmux new-session -s $selected_name -c $selected |
| 18 | exit 0 |
| 19 | fi |
| 20 | |
| 21 | if ! tmux has-session -t=$selected_name 2> /dev/null; then |
| 22 | tmux new-session -ds $selected_name -c $selected |
| 23 | fi |
| 24 | |
| 25 | tmux switch-client -t $selected_name |