Last active
November 16, 2023 09:51
-
-
Save dhernandez/7e53e55aadb7f16bf41780620911f3fc to your computer and use it in GitHub Desktop.
yarn <tab><tab> autocomplete with yarn commands from yarn --help. yarn run <tab><tab> autocomplete with scripts from package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
_yarn(){ | |
if [ "$2" = "" ]; then SEARCH_PATTERN="."; else SEARCH_PATTERN=$2 | |
fi | |
if [ "$3" == "run" ]; then | |
COMPREPLY=( $(cat package.json | jq '.scripts | keys[]' | tr -d \" | grep -E ^$SEARCH_PATTERN | tr \\n ' ') ) | |
else | |
COMPREPLY=( $(yarn --help | grep -e "-\s" | tr -d '\- ' | grep -E ^$SEARCH_PATTERN | tr -d ' ' | tr \\n ' ') ) | |
fi | |
} | |
complete -F _yarn yarn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment