lando.plugin.zsh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Settings
  2. : ${LANDO_ZSH_SITES_DIRECTORY:="$HOME/Sites"}
  3. : ${LANDO_ZSH_CONFIG_FILE:=.lando.yml}
  4. # Enable multiple commands with lando.
  5. function artisan \
  6. composer \
  7. drush \
  8. gulp \
  9. npm \
  10. php \
  11. wp \
  12. yarn {
  13. # If the lando task is available in `lando --help`, then it means:
  14. #
  15. # 1. `lando` is in a project with a `.lando.yml` file.
  16. # 2. The lando task is available for lando, based on the .lando.yml config file.
  17. #
  18. # This has a penalty of about 250ms, so we still want to check if the lando file
  19. # exists before, which is the fast path. If it exists, checking help output is
  20. # still faster than running the command and failing.
  21. if _lando_file_exists && lando --help 2>&1 | command grep -Eq "^ +lando $0 "; then
  22. command lando "$0" "$@"
  23. else
  24. command "$0" "$@"
  25. fi
  26. }
  27. # Check for the file in the current and parent directories.
  28. _lando_file_exists() {
  29. # Only bother checking for lando within the Sites directory.
  30. if [[ "$PWD/" != "$LANDO_ZSH_SITES_DIRECTORY"/* ]]; then
  31. # Not within $LANDO_ZSH_SITES_DIRECTORY
  32. return 1
  33. fi
  34. local curr_dir="$PWD"
  35. # Checking for file: $LANDO_ZSH_CONFIG_FILE within $LANDO_ZSH_SITES_DIRECTORY...
  36. while [[ "$curr_dir" != "$LANDO_ZSH_SITES_DIRECTORY" ]]; do
  37. if [[ -f "$curr_dir/$LANDO_ZSH_CONFIG_FILE" ]]; then
  38. return 0
  39. fi
  40. curr_dir="${curr_dir:h}"
  41. done
  42. # Could not find $LANDO_ZSH_CONFIG_FILE in the current directory
  43. # or in any of its parents up to $LANDO_ZSH_SITES_DIRECTORY.
  44. return 1
  45. }