Created
August 9, 2021 13:27
-
-
Save ryaninvents/d9155214c91d18ddae3da021d3a13c99 to your computer and use it in GitHub Desktop.
ZSH Yarn autocomplete
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
# 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