Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@artemave 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
You can’t perform that action at this time.