3 ms·
I love fzf as well. I use it with the npm package manager to select the script to run (we have an app with 20+ scripts): npmrf () { local script
by jugjug 6y ago
I love fzf as well. I use it with the npm package manager to select the script to run (we have an app with 20+ scripts):
npmrf () {
local script
script=$(cat package.json | jq -r '.scripts | keys[] ' | sort | fzf) && npm run $script
}
Another usecase is tracking hours with Clockify. I was frustrated opening up the web everytime, so I wrote a script using fzf, httpie and jq. Love it now. [1]
[1]: https://marcel.is/tracking-hours/ https://marcel.is/tracking-hours/
- mssundaram 6y agoThat's a great idea, thanks. Do you know how to get it to show the preview window with the script value? Sometimes I need to explore which script task I need based on what it does
- jugjug 6y agoYeah, that would be nice. I don't know though from the top of my head.
- zjmil 6y agoYou could do something like this (not super thoroughly tested): npmrf () { local script script=$(jq -r '.scripts | to_entries[] | "\(.key) => \(.value)"' < package.json | sort | fzf | cut -d' ' -f1) && npm run "$script" } It uses jq's to_entries to pull out the script/command key pairs and then just cuts out the script name after you choose the command (assumes the command name doesn't have spaces).