lando.plugin.zsh 1.5 KB

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