pj.plugin.zsh 594 B

12345678910111213141516171819202122232425262728293031323334353637
  1. alias pjo="pj open"
  2. pj () {
  3. emulate -L zsh
  4. cmd="cd"
  5. project=$1
  6. if [[ "open" == "$project" ]]; then
  7. shift
  8. project=$*
  9. cmd=${=EDITOR}
  10. else
  11. project=$*
  12. fi
  13. for basedir ($PROJECT_PATHS); do
  14. if [[ -d "$basedir/$project" ]]; then
  15. $cmd "$basedir/$project"
  16. return
  17. fi
  18. done
  19. echo "No such project '${project}'."
  20. }
  21. _pj () {
  22. emulate -L zsh
  23. typeset -a projects
  24. for basedir ($PROJECT_PATHS); do
  25. projects+=(${basedir}/*(/N))
  26. done
  27. compadd ${projects:t}
  28. }
  29. compdef _pj pj