From dc019bc3ecf17495147deea42d30ef15cc089b68 Mon Sep 17 00:00:00 2001 From: Adrian Wojdat Date: Wed, 22 Feb 2023 22:50:58 +0100 Subject: [PATCH] feat(adwnode): add plugin --- plugins/adwnode/LICENSE | 21 +++++++++++++++++++++ plugins/adwnode/README.md | 14 ++++++++++++++ plugins/adwnode/_adwnode | 17 +++++++++++++++++ plugins/adwnode/adwnode.plugin.zsh | 3 +++ 4 files changed, 55 insertions(+) create mode 100644 plugins/adwnode/LICENSE create mode 100644 plugins/adwnode/README.md create mode 100644 plugins/adwnode/_adwnode create mode 100644 plugins/adwnode/adwnode.plugin.zsh diff --git a/plugins/adwnode/LICENSE b/plugins/adwnode/LICENSE new file mode 100644 index 000000000..e1353fb77 --- /dev/null +++ b/plugins/adwnode/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023-present Adrian Wojdat + +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/adwnode/README.md b/plugins/adwnode/README.md new file mode 100644 index 000000000..89b2d23cf --- /dev/null +++ b/plugins/adwnode/README.md @@ -0,0 +1,14 @@ +# NodeJs - Scripts autocomplete + +

NodeJs Autocompleter

+ +## Instalation +To use it, add `adwnode` to the plugins array in your .zshrc file: + +```shell +plugins=(... adwnode) +``` + +## Usage +Just start typing `yarn` or `npm run` inside NodeJs app directory and double press tab key to start autocompleter. +

NodeJs Autocompleter

diff --git a/plugins/adwnode/_adwnode b/plugins/adwnode/_adwnode new file mode 100644 index 000000000..e7e0077bc --- /dev/null +++ b/plugins/adwnode/_adwnode @@ -0,0 +1,17 @@ +_load_nodejs_scripts() { + local read_package_json_scripts_command="try { Object.keys(require('./package.json').scripts).join('\n').replace(/:/g, '\\\:') } catch {''}" + nodejs_scripts=("${(@f)$(node -pe ${read_package_json_scripts_command} | sort)}") +} + +_adwnode() { + if command -v node >/dev/null 2>&1; then + if [ -f ./package.json ]; then + _load_nodejs_scripts + + + if [[ ! ${#nodejs_scripts[@]} -eq 0 ]]; then + _describe '' nodejs_scripts + fi + fi + fi +} \ No newline at end of file diff --git a/plugins/adwnode/adwnode.plugin.zsh b/plugins/adwnode/adwnode.plugin.zsh new file mode 100644 index 000000000..4140a2e78 --- /dev/null +++ b/plugins/adwnode/adwnode.plugin.zsh @@ -0,0 +1,3 @@ +autoload -Uz _adwnode +compdef _adwnode yarn +compdef _adwnode npm run \ No newline at end of file