d082d87580f05cca524c546d54eb8009cf8bb10c

Author
Marc Cornellà <marc@mcornella.com>
Committer
Marc Cornellà <marc@mcornella.com>
Date

Message

refactor(lando): add `LANDO_ZSH_WRAPPED_COMMANDS` setting and refactor

Diff

 1diff --git a/plugins/lando/README.md b/plugins/lando/README.md
 2index 6daeae4e494dedac3ccbc43a38832d6903df473c..2f881cf3dfdf83382b39ff9e62c328835fb8b0ca 100644
 3--- a/plugins/lando/README.md
 4+++ b/plugins/lando/README.md
 5@@ -8,7 +8,7 @@ To use it, add `lando` to the plugins array in your zshrc file:
 6 plugins=(... lando)
 7 ```
 8 
 9-## ALIASES:
10+## Wrapped Commands
11 
12 | Alias      | Description      |
13 |:----------:|:----------------:|
14@@ -21,16 +21,34 @@ plugins=(... lando)
15 | `wp`       | `lando wp`       |
16 | `yarn`     | `lando yarn`     |
17 
18+More or different commands can be wrapped by setting the `LANDO_ZSH_WRAPPED_COMMANDS` setting, see [Settings](#settings) below.
19+
20 ## How It Works:
21 
22 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:
23+
24 - The `.lando.yml` file is found in the current directory or any parent directory within `$LANDO_ZSH_SITES_DIRECTORY`.
25 - The current directory is within `$LANDO_ZSH_SITES_DIRECTORY` but is not `$LANDO_ZSH_SITES_DIRECTORY` itself.
26+- If the command is not a part of the commands available in the lando environment, it will run the command without `lando`.
27 
28 ## Settings:
29 
30-- `LANDO_ZSH_SITES_DIRECTORY`: The plugin will stop searching through parents for `CONFIG_FILE` once it hits this directory.
31-- `LANDO_ZSH_CONFIG_FILE`: The plugin will check to see if this provided file exists to check for presence of Lando.
32+> NOTE: these settings must be set *before* the plugin is loaded, and any changes require a restart of the shell to be applied.
33+
34+- `LANDO_ZSH_SITES_DIRECTORY`: The plugin will stop searching through parents for `CONFIG_FILE` once it hits this directory:
35+  ```sh
36+  LANDO_ZSH_SITES_DIRECTORY="$HOME/Code"
37+  ```
38+
39+- `LANDO_ZSH_CONFIG_FILE`: The plugin will check to see if this provided file exists to check for presence of Lando:
40+  ```sh
41+  LANDO_ZSH_CONFIG_FILE=".lando.dev.yml"
42+  ```
43+
44+- `LANDO_ZSH_WRAPPED_COMMANDS`: The list of commands to wrap, as a string of commands separated by whitespace:
45+  ```sh
46+  LANDO_ZSH_WRAPPED_COMMANDS="mysql php composer test artisan"
47+  ```
48 
49 ## Author:
50 
51diff --git a/plugins/lando/lando.plugin.zsh b/plugins/lando/lando.plugin.zsh
52index b5fa800926e01acbf8b9ed305ec1ad700c2751cd..ee796d2128bf4e44a4a89e586e0e3f5e8379d119 100644
53--- a/plugins/lando/lando.plugin.zsh
54+++ b/plugins/lando/lando.plugin.zsh
55@@ -1,16 +1,19 @@
56 # Settings
57 : ${LANDO_ZSH_SITES_DIRECTORY:="$HOME/Sites"}
58 : ${LANDO_ZSH_CONFIG_FILE:=.lando.yml}
59+: ${LANDO_ZSH_WRAPPED_COMMANDS:="
60+  artisan
61+  composer
62+  drush
63+  gulp
64+  npm
65+  php
66+  wp
67+  yarn
68+"}
69 
70 # Enable multiple commands with lando.
71-function artisan \
72-         composer \
73-         drush \
74-         gulp \
75-         npm \
76-         php \
77-         wp \
78-         yarn {
79+function ${=LANDO_ZSH_WRAPPED_COMMANDS} {
80   # If the lando task is available in `lando --help`, then it means:
81   #
82   # 1. `lando` is in a project with a `.lando.yml` file.