Arch 2025 rice. Also contains a newly inspired neovim config.
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.

70 lines
1.5 KiB

2 weeks ago
  1. #!/usr/bin/env sh
  2. WORKSPACES=${WORKSPACES:-$HOME/Documents:$HOME/docs/prg}
  3. IFS=':' findargs=$WORKSPACES
  4. while test $# -gt 0; do
  5. case "$1" in
  6. -d|--depth)
  7. shift
  8. if test -z "$1"; then
  9. echo "No appropriate option given after depth"
  10. exit 1
  11. else
  12. depth="$1"
  13. fi
  14. shift;
  15. ;;
  16. -*)
  17. echo "Invalid option $1"
  18. exit 1
  19. ;;
  20. *)
  21. sessiondir="$1"
  22. shift;
  23. ;;
  24. esac
  25. done
  26. if test -z "$sessiondir"; then
  27. if ! test -z "$depth" && test "$depth" -eq 0; then
  28. sessiondir="$(find $findargs\
  29. \! -name '*.git*'\
  30. \! -name '*.vscode*'\
  31. \! -name '*.idea*'\
  32. \! -name '*node_modules*'\
  33. \! -name '*__pycache__*'\
  34. \! -name '*venv*'\
  35. -type d 2>/dev/null | fzf)"
  36. else
  37. sessiondir="$(find $findargs -maxdepth ${depth:-2}\
  38. \! -name '*.git*'\
  39. \! -name '*.vscode*'\
  40. \! -name '*.idea*'\
  41. \! -name '*node_modules*'\
  42. \! -name '*__pycache__*'\
  43. \! -name '*venv*'\
  44. -type d 2>/dev/null | fzf)"
  45. fi
  46. fi
  47. if test -z "$sessiondir" || ! test -d "$sessiondir"; then
  48. echo "$sessiondir is not a directory. Aborting..."
  49. exit 0
  50. fi
  51. name="$(realpath "$sessiondir" | tr '.' '_')"
  52. if test -z "$TMUX" && test -z "$(pgrep tmux)"; then
  53. tmux new-session -c "$sessiondir" -s "$name"
  54. else
  55. if ! tmux has-session -t="$name" 2> /dev/null; then
  56. tmux new-session -d -c "$sessiondir" -s "$name"
  57. fi
  58. if test -z "$TMUX"; then
  59. tmux attach -t "$name"
  60. else
  61. tmux switch-client -t "$name"
  62. fi
  63. fi