Created
April 16, 2024 13:33
-
-
Save griffgruff/ae0188cb7bbff341dd378a4593d468e5 to your computer and use it in GitHub Desktop.
Revisions
-
griffgruff created this gist
Apr 16, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/usr/bin/env bash # Getting tired of not knowing which npm command to run # Well this is the answer # It does use fzf. # First off, this script allow us to just type : run # Then you can just filter by command # I was using ntl, but it is/was super slow. # jq is another thing you might have to install # jq is a command line json processor # jq .script will give use the scripts section # sed then does some search and replace magic # It's then all just piped to fzf # Read the package.json file if cat package.json > /dev/null 2>&1; then scripts=$(cat package.json | jq .scripts | sed '1d;$d' | fzf --height 40%) if [[ -n $scripts ]]; then script_name=$(echo $scripts | awk -F ': ' '{gsub(/"/, "", $1); print $1}') echo -s "npm run "$script_name; npm run $script_name else echo "Exit: You haven't selected any script" fi else # Error if package, json not found echo "Error: There's no package.json" fi