From 65419fa13c49199a4b6246207ee9e2896229f0aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Appel?= Date: Wed, 13 Sep 2023 21:17:31 +0200 Subject: [PATCH] feat: adds the Laravel Sail plugin --- plugins/sail/LICENSE | 22 ++++++++++++++++++++ plugins/sail/README.md | 40 ++++++++++++++++++++++++++++++++++++ plugins/sail/sail.plugin.zsh | 30 +++++++++++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 plugins/sail/LICENSE create mode 100644 plugins/sail/README.md create mode 100644 plugins/sail/sail.plugin.zsh diff --git a/plugins/sail/LICENSE b/plugins/sail/LICENSE new file mode 100644 index 000000000..d11547eb5 --- /dev/null +++ b/plugins/sail/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2019 Joshua Bedford +Copyright (c) 2023 Marc-André Appel + +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. diff --git a/plugins/sail/README.md b/plugins/sail/README.md new file mode 100644 index 000000000..72a7d3fd6 --- /dev/null +++ b/plugins/sail/README.md @@ -0,0 +1,40 @@ +# Laravel Sail Oh-My-Zsh plugin + +This [OMZ plugin](https://github.com/ohmyzsh/ohmyzsh/wiki/Plugins) adds aliases for typical commands with [Laravel Sail](https://laravel.com/docs/10.x/sail). It will only run within sail-driven project directories. + +To use it, add `sail` to the oh-my-zsh plugins array in your `.zshrc` file: + +```zsh +plugins=(... sail) +``` + +## Commands + +| Alias | Description | +|:----------:|:---------------:| +| `artisan` | `sail artisan` | +| `composer` | `sail composer` | +| `node` | `sail node` | +| `npm` | `sail npm` | +| `npx` | `sail npx` | +| `php` | `sail php` | +| `yarn` | `sail yarn` | + +## How it works + +This plugin removes the requirement to type `sail` before a command. It utilizes the sail version of supported commands run within directories where the `sail` command is found in the `vendor/bin` directory. + +## Settings + +The plugin will utilize the default values. Set the variable(s) below as needed in your .zshrc file to change these default values to match your development environment: + +- `SAIL_ZSH_BIN_PATH`: The plugin will check to see if this provided path exists to check for presence of Laravel Sail. By default, the path is `vendor/bin/sail` but this can be changed if needed. + +## Authors + +- [Marc-André Appel](https://maa.rocks) +- [https://github.com/marcandreappel/sail-zsh](https://github.com/marcandreappel/sail-zsh) + +- Joshua Bedford (Author of the original Lando plugin) +- URL: [https://github.com/joshuabedford/lando-zsh](https://github.com/joshuabedford/lando-zsh) + diff --git a/plugins/sail/sail.plugin.zsh b/plugins/sail/sail.plugin.zsh new file mode 100644 index 000000000..ac1a845ae --- /dev/null +++ b/plugins/sail/sail.plugin.zsh @@ -0,0 +1,30 @@ +# Laravel Sail ZSH plugin +# +# Setting +: ${SAIL_ZSH_BIN_PATH:="./vendor/bin/sail"} + +# Enable multiple commands with sail +function artisan \ + composer \ + node \ + npm \ + npx \ + php \ + yarn { + if checkForSail; then + $SAIL_ZSH_BIN_PATH "$0" "$@" + else + command "$0" "$@" + fi +} + +# Check for the file in the current and parent directories. +checkForSail() { + # Check if ./vendor directory exists and if ./vendor/bin/sail file exists. + if [ -f $SAIL_ZSH_BIN_PATH ]; then + return 0 + else + # Could not find $SAIL_ZSH_BIN_PATH in the current directory + return 1 + fi +}