Skip to content

Instantly share code, notes, and snippets.

@ryaninvents
Created August 9, 2021 13:27
Show Gist options
  • Save ryaninvents/d9155214c91d18ddae3da021d3a13c99 to your computer and use it in GitHub Desktop.
Save ryaninvents/d9155214c91d18ddae3da021d3a13c99 to your computer and use it in GitHub Desktop.
ZSH Yarn autocomplete
# source this from your ~/.zshrc for Yarn autocompletion
# this won't suggest standard Yarn commands (add, upgrade, etc) but will show you custom commands for this project
# make sure you have jq installed
function _yarn() {
local scripts=$(jq -r '.scripts | to_entries | '\
'map(.key |= sub(":";"\\:";"g")) | '\
'.[] | '\
'[select((.value | length) > 0)] | '\
'select((. | length) > 0) | '\
'map("'"'"'\(.key):\(.value)'"'"'") | '\
'join(" ")' < package.json)
_describe 'command' "($scripts)"
}
compdef _yarn yarn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment