Created
June 29, 2025 21:00
-
-
Save code-inflation/98f743340831623bcb255c51f28e598e to your computer and use it in GitHub Desktop.
Fuzzy find and switch to tmux sessions for git repositories
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Fuzzy find and switch to tmux sessions for git repositories | |
| # Usage: tmux-sessionizer [directory] | |
| # If no directory provided, opens fzf to select from ~/git subdirectories | |
| function tmux-sessionizer | |
| if test (count $argv) -eq 1 | |
| set selected $argv[1] | |
| else | |
| set selected (find ~/git -mindepth 1 -maxdepth 1 -type d | fzf) | |
| end | |
| if test -z "$selected" | |
| return 0 | |
| end | |
| set selected_name (basename "$selected" | tr . _) | |
| set tmux_running (pgrep tmux) | |
| if test -z "$TMUX" -a -z "$tmux_running" | |
| tmux new-session -s $selected_name -c $selected | |
| return 0 | |
| end | |
| if not tmux has-session -t=$selected_name 2>/dev/null | |
| tmux new-session -ds $selected_name -c $selected | |
| end | |
| tmux switch-client -t $selected_name | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment