Skip to content

Instantly share code, notes, and snippets.

@metalsp0rk
Created December 10, 2023 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metalsp0rk/0ca9f6395561330757f9ea7425ff9023 to your computer and use it in GitHub Desktop.
Save metalsp0rk/0ca9f6395561330757f9ea7425ff9023 to your computer and use it in GitHub Desktop.
tmux-sessionizer
#!/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