You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
693 B

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