Skip to content

Instantly share code, notes, and snippets.

@arnaudcourtecuisse
Last active June 1, 2018 09:41
Show Gist options
  • Save arnaudcourtecuisse/eb26b80430d34f24a2d73cda04751c1e to your computer and use it in GitHub Desktop.
Save arnaudcourtecuisse/eb26b80430d34f24a2d73cda04751c1e to your computer and use it in GitHub Desktop.
Basic yarn bash completion for commands and scripts (place file in /etc/bash_completion.d/)
_yarn() {
local cur prev commands scripts opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
commands="access add autoclean bin cache check config create exec generate-lock-entry global\
help import info init install licenses link list login logout node outdated owner pack publish\
remove run tag team unlink upgrade upgrade-interactive version versions why workspace workspaces"
scripts=$(jq .scripts package.json | jq -r keys[])
opts="$commands $scripts"
[ "$prev" = "yarn" ] && { COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ); return 0; }
[ "$prev" = "run" ] && { COMPREPLY=( $(compgen -W "${scripts}" -- ${cur}) ); return 0; }
}
complete -F _yarn yarn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment