Skip to content

Instantly share code, notes, and snippets.

@mxdevmanuel
Created January 4, 2020 19:02
Show Gist options
  • Save mxdevmanuel/ed9d48629f469752c81c8277b19eb32c to your computer and use it in GitHub Desktop.
Save mxdevmanuel/ed9d48629f469752c81c8277b19eb32c to your computer and use it in GitHub Desktop.
Run npm script from within vim with popup_menu
func NpmSelected(id, result)
let cmd = "npm run " . b:ks[a:result - 1]
exec "terminal " . cmd
endfunc
function! RunNpm()
if filereadable("./package.json")
let st = readfile("./package.json")
let package = json_decode(join(st, " "))
if has_key(package, "scripts")
let b:ks = keys(package.scripts)
call popup_menu(b:ks, #{callback: 'NpmSelected'})
endif
else
echo "No package.json found"
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment