Re:Fzf – the basics part 1 – layout
by mssundaram on Friday February 05, 2021 @09:54AM
(#26036913)
That'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
You 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).
[1]: https://marcel.is/tracking-hours/