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.

27 lines
649 B

2 years ago
  1. #!/usr/bin/env sh
  2. WORKSPACES=${WORKSPACES:-$HOME/Documents}
  3. IFS=':' findargs=$WORKSPACES
  4. if test -z "$1"; then
  5. sessiondir="$(find $findargs -maxdepth 2 -type d 2>/dev/null | fzf)"
  6. else
  7. sessiondir="$1"
  8. fi
  9. if test -z "$sessiondir" || ! test -d "$sessiondir"; then
  10. echo "$sessiondir is not a directory. Aborting..."
  11. exit 0
  12. fi
  13. name="$(basename "$(realpath "$sessiondir" )" | tr '.' '_')"
  14. if test -z "$TMUX" && test -z "$(pgrep tmux)"; then
  15. tmux new-session -c "$sessiondir" -s "$name"
  16. else
  17. if ! tmux has-session -t="$name" 2> /dev/null; then
  18. tmux new-session -d -c "$sessiondir" -s "$name"
  19. fi
  20. tmux switch-client -t "$name"
  21. fi