Created
December 10, 2023 20:23
-
-
Save metalsp0rk/0ca9f6395561330757f9ea7425ff9023 to your computer and use it in GitHub Desktop.
tmux-sessionizer
This file contains 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
#!/usr/bin/env bash | |
if [[ $# -eq 1 ]]; then | |
selected=$(find -L ~/code -mindepth 1 -maxdepth 1 -type d | sed "s,$HOME/code/,," | fzf -q "$1") | |
else | |
selected=$(find -L ~/code -mindepth 1 -maxdepth 1 -type d | sed "s,$HOME/code/,," | fzf) | |
fi | |
if [[ -z $selected ]]; then | |
exit 0 | |
fi | |
selected=$HOME/code/$selected | |
selected_name=$(basename "$selected" | tr . _) | |
tmux_running=$(pgrep tmux) | |
if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then | |
tmux new-session -s $selected_name -c $selected | |
exit 0 | |
fi | |
if ! tmux has-session -t=$selected_name 2> /dev/null; then | |
tmux new-session -ds $selected_name -c $selected | |
fi | |
tmux switch-client -t $selected_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment