Skip to content

Instantly share code, notes, and snippets.

@nucliweb
Created September 15, 2023 21:49
Show Gist options
  • Save nucliweb/b421517aa73f02339b960e3d5f875298 to your computer and use it in GitHub Desktop.
Save nucliweb/b421517aa73f02339b960e3d5f875298 to your computer and use it in GitHub Desktop.
List and select npm scripts
## Requisites
## fzf https://github.com/junegunn/fzf
## jq https://jqlang.github.io/jq/
_nr () {
local cmd
local TASK=$(npm run | egrep '^\s' | awk '{gsub(/ /,""); print}' | awk 'NR%2==1' | fzf --preview 'jq .scripts package.json' | awk '{gsub(/ /,""); print}')
if [ -n "$TASK" ]; then
cmd="npm run \"$TASK\""
eval "$cmd" &
fi
}
zle -N _nr
bindkey '^o' _nr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment