pj.plugin.zsh 511 B

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