Skip to content

Instantly share code, notes, and snippets.

@zmzlois
Created April 24, 2024 02:15
Show Gist options
  • Select an option

  • Save zmzlois/b875cef441dece6942445124559f2544 to your computer and use it in GitHub Desktop.

Select an option

Save zmzlois/b875cef441dece6942445124559f2544 to your computer and use it in GitHub Desktop.
npm-for-monorepo
function genme() {
local package=$1
local output=$(pnpm search --json ${package} | jq -r 'map( { name, description, command: ("pnpm add " + .name) } )')
local fzf_input=$(echo "${output}" | jq -r '.[] | "\(.name) - \(.description)"')
local selected=$(echo "$fzf_input" | fzf)
# If nothing was selected, exit
if [[ -z "$selected" ]]; then
echo "No package selected."
return
fi
local selected_name=$(echo "$selected" | cut -d' ' -f1)
local command=$(echo "${output}" | jq -r --arg PACKAGE "$selected_name" '.[] | select(.name == $PACKAGE) | .command')
echo "You selected: $command"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment