4cd5f7f9202bd062871662836ea837c9abea6e5d

Author
Joshua Bedford <joshua@joshuabedford.com>
Committer
GitHub <noreply@github.com>
Date

Message

Add lando plugin (#8748)

Co-authored-by: Joshua Bedford <joshua.bedford@hurstreview.com>
Co-authored-by: Marc Cornellà <marc.cornella@live.com>

Diff

  1diff --git a/plugins/lando/LICENSE b/plugins/lando/LICENSE
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..1d4983163f08ea7c6d8c494202a0be27b9058fc5
  4--- /dev/null
  5+++ b/plugins/lando/LICENSE
  6@@ -0,0 +1,21 @@
  7+MIT License
  8+
  9+Copyright (c) 2019 Joshua Bedford
 10+
 11+Permission is hereby granted, free of charge, to any person obtaining a copy
 12+of this software and associated documentation files (the "Software"), to deal
 13+in the Software without restriction, including without limitation the rights
 14+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 15+copies of the Software, and to permit persons to whom the Software is
 16+furnished to do so, subject to the following conditions:
 17+
 18+The above copyright notice and this permission notice shall be included in all
 19+copies or substantial portions of the Software.
 20+
 21+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 22+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 23+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 24+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 25+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 26+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 27+SOFTWARE.
 28diff --git a/plugins/lando/README.md b/plugins/lando/README.md
 29new file mode 100644
 30index 0000000000000000000000000000000000000000..928a42bca2132cae4a2acf6921e770139dfa7221
 31--- /dev/null
 32+++ b/plugins/lando/README.md
 33@@ -0,0 +1,37 @@
 34+# Lando ZSH (lando-zsh)
 35+
 36+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.
 37+
 38+To use it, add `lando` to the plugins array in your zshrc file:
 39+
 40+```zsh
 41+plugins=(... lando)
 42+```
 43+
 44+## ALIASES:
 45+
 46+| Alias      | Description      |
 47+|:----------:|:----------------:|
 48+| `artisan`  | `lando artisan`  |
 49+| `composer` | `lando composer` |
 50+| `drush`    | `lando drush`    |
 51+| `gulp`     | `lando gulp`     |
 52+| `npm`      | `lando npm`      |
 53+| `wp`       | `lando wp`       |
 54+| `yarn`     | `lando yarn`     |
 55+
 56+## How It Works:
 57+
 58+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:
 59+- The `.lando.yml` file is found in the current directory or any parent directory within `$LANDO_ZSH_SITES_DIRECTORY`.
 60+- The current directory is within `$LANDO_ZSH_SITES_DIRECTORY` but is not `$LANDO_ZSH_SITES_DIRECTORY` itself.
 61+
 62+## Settings:
 63+
 64+- `LANDO_ZSH_SITES_DIRECTORY`: The plugin will stop searching through parents for `CONFIG_FILE` once it hits this directory.
 65+- `LANDO_ZSH_CONFIG_FILE`: The plugin will check to see if this provided file exists to check for presence of Lando.
 66+
 67+## Author:
 68+
 69+- Author: Joshua Bedford
 70+- URL: [https://github.com/joshuabedford/lando-zsh](https://github.com/joshuabedford/lando-zsh)
 71diff --git a/plugins/lando/lando.plugin.zsh b/plugins/lando/lando.plugin.zsh
 72new file mode 100644
 73index 0000000000000000000000000000000000000000..aa74c992454b1b4df78fadef861aeb308e00761a
 74--- /dev/null
 75+++ b/plugins/lando/lando.plugin.zsh
 76@@ -0,0 +1,40 @@
 77+# Settings
 78+: ${LANDO_ZSH_SITES_DIRECTORY:="$HOME/Sites"}
 79+: ${LANDO_ZSH_CONFIG_FILE:=.lando.yml}
 80+
 81+# Enable multiple commands with lando.
 82+function artisan \
 83+         composer \
 84+         drush \
 85+         gulp \
 86+         npm \
 87+         wp \
 88+         yarn {
 89+  if checkForLandoFile; then
 90+    lando "$0" "$@"
 91+  else
 92+    command "$0" "$@"
 93+  fi
 94+}
 95+
 96+# Check for the file in the current and parent directories.
 97+checkForLandoFile() {
 98+  # Only bother checking for lando within the Sites directory.
 99+  if [[ "$PWD/" != "$LANDO_ZSH_SITES_DIRECTORY"/* ]]; then
100+    # Not within $LANDO_ZSH_SITES_DIRECTORY
101+    return 1
102+  fi
103+
104+  local curr_dir="$PWD"
105+  # Checking for file: $LANDO_ZSH_CONFIG_FILE within $LANDO_ZSH_SITES_DIRECTORY...
106+  while [[ "$curr_dir" != "$LANDO_ZSH_SITES_DIRECTORY" ]]; do
107+    if [[ -f "$curr_dir/$LANDO_ZSH_CONFIG_FILE" ]]; then
108+      return 0
109+    fi
110+    curr_dir="${curr_dir:h}"
111+  done
112+
113+  # Could not find $LANDO_ZSH_CONFIG_FILE in the current directory
114+  # or in any of its parents up to $LANDO_ZSH_SITES_DIRECTORY.
115+  return 1
116+}