Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Last active June 7, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewVos/342e37616713e8bfe1bc3cd556e64b64 to your computer and use it in GitHub Desktop.
Save AndrewVos/342e37616713e8bfe1bc3cd556e64b64 to your computer and use it in GitHub Desktop.
Yarn completion for anything in "scripts". Add it to your .bashrc or whatever. Requires jq
_yarn_complete() {
local cur_word prev_word scripts
cur_word="${COMP_WORDS[COMP_CWORD]}"
prev_word="${COMP_WORDS[COMP_CWORD-1]}"
scripts=$(jq '.scripts | keys[]' package.json | paste)
COMPREPLY=( $(compgen -W "${scripts}" -- ${cur_word}) )
return 0
}
complete -F _yarn_complete yarn
@artemave
Copy link

artemave commented Jun 7, 2018

Nice! You could remove dependency on jq:

scripts=$(node -e 'Object.keys(require("./package.json").scripts).forEach(s => console.log(s))')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment