Skip to content

Instantly share code, notes, and snippets.

@CalebBarnes
Last active January 31, 2024 22:22
Show Gist options
  • Select an option

  • Save CalebBarnes/bc8e414ad560c4655b2629e85605a838 to your computer and use it in GitHub Desktop.

Select an option

Save CalebBarnes/bc8e414ad560c4655b2629e85605a838 to your computer and use it in GitHub Desktop.
swpm tab completion for scripts in package.json (works with command alias)
# 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
@CalebBarnes
Copy link
Author

2024-01-22.02-29-03.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment