diff --git a/plugins/lando/LICENSE b/plugins/lando/LICENSE new file mode 100644 index 000000000..1d4983163 --- /dev/null +++ b/plugins/lando/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Joshua Bedford + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/plugins/lando/README.md b/plugins/lando/README.md new file mode 100644 index 000000000..928a42bca --- /dev/null +++ b/plugins/lando/README.md @@ -0,0 +1,37 @@ +# Lando ZSH (lando-zsh) + +This plugin adds aliases for using various languages and frameworks with [Lando](https://docs.lando.dev/basics/) for Docker. It will only run within lando-driven project directories. + +To use it, add `lando` to the plugins array in your zshrc file: + +```zsh +plugins=(... lando) +``` + +## ALIASES: + +| Alias | Description | +|:----------:|:----------------:| +| `artisan` | `lando artisan` | +| `composer` | `lando composer` | +| `drush` | `lando drush` | +| `gulp` | `lando gulp` | +| `npm` | `lando npm` | +| `wp` | `lando wp` | +| `yarn` | `lando yarn` | + +## How It Works: + +This plugin removes the requirement to type `lando` before a command. It utilizes the lando version of supported commands run within directories with the following criteria: +- The `.lando.yml` file is found in the current directory or any parent directory within `$LANDO_ZSH_SITES_DIRECTORY`. +- The current directory is within `$LANDO_ZSH_SITES_DIRECTORY` but is not `$LANDO_ZSH_SITES_DIRECTORY` itself. + +## Settings: + +- `LANDO_ZSH_SITES_DIRECTORY`: The plugin will stop searching through parents for `CONFIG_FILE` once it hits this directory. +- `LANDO_ZSH_CONFIG_FILE`: The plugin will check to see if this provided file exists to check for presence of Lando. + +## Author: + +- Author: Joshua Bedford +- URL: [https://github.com/joshuabedford/lando-zsh](https://github.com/joshuabedford/lando-zsh) diff --git a/plugins/lando/lando.plugin.zsh b/plugins/lando/lando.plugin.zsh new file mode 100644 index 000000000..aa74c9924 --- /dev/null +++ b/plugins/lando/lando.plugin.zsh @@ -0,0 +1,40 @@ +# Settings +: ${LANDO_ZSH_SITES_DIRECTORY:="$HOME/Sites"} +: ${LANDO_ZSH_CONFIG_FILE:=.lando.yml} + +# Enable multiple commands with lando. +function artisan \ + composer \ + drush \ + gulp \ + npm \ + wp \ + yarn { + if checkForLandoFile; then + lando "$0" "$@" + else + command "$0" "$@" + fi +} + +# Check for the file in the current and parent directories. +checkForLandoFile() { + # Only bother checking for lando within the Sites directory. + if [[ "$PWD/" != "$LANDO_ZSH_SITES_DIRECTORY"/* ]]; then + # Not within $LANDO_ZSH_SITES_DIRECTORY + return 1 + fi + + local curr_dir="$PWD" + # Checking for file: $LANDO_ZSH_CONFIG_FILE within $LANDO_ZSH_SITES_DIRECTORY... + while [[ "$curr_dir" != "$LANDO_ZSH_SITES_DIRECTORY" ]]; do + if [[ -f "$curr_dir/$LANDO_ZSH_CONFIG_FILE" ]]; then + return 0 + fi + curr_dir="${curr_dir:h}" + done + + # Could not find $LANDO_ZSH_CONFIG_FILE in the current directory + # or in any of its parents up to $LANDO_ZSH_SITES_DIRECTORY. + return 1 +} \ No newline at end of file