Last active
January 31, 2024 22:22
-
-
Save CalebBarnes/bc8e414ad560c4655b2629e85605a838 to your computer and use it in GitHub Desktop.
swpm tab completion for scripts in package.json (works with command alias)
This file contains hidden or 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
| # optionally add custom command alias for swpm | |
| alias p="swpm" | |
| # define completion after your command alias | |
| autoload -Uz compinit && compinit # omit this if it is included above^ in your zshrc | |
| _swpm_scripts() { | |
| local package_file="package.json" | |
| if [[ -f $package_file ]]; then | |
| local -a scripts | |
| scripts=(${(f)"$(node -e "const package = require('./$package_file'); console.log(Object.keys(package.scripts).join('\n'));")"}) | |
| compadd -a scripts | |
| fi | |
| } | |
| compdef _swpm_scripts swpm |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2024-01-22.02-29-03.mp4