Skip to content

Instantly share code, notes, and snippets.

@vyashole
Last active June 27, 2025 11:03
Show Gist options
  • Save vyashole/31b38cc4c9c91c2a205e583cadc3f3f0 to your computer and use it in GitHub Desktop.
Save vyashole/31b38cc4c9c91c2a205e583cadc3f3f0 to your computer and use it in GitHub Desktop.
Interactive brew search and install with FZF

Brew+FZF = Interactive search and install

Runs brew search for the given arguments, allows you to select a package from the search with fzf, installs the package with brew install.

Usage

source brew_fzf_install.zsh 

Source this script in your .zshrc (you may or may not need modifications to use this with bash or other shells, I don't know)

# Interactive brew search and install function
# Dependencies: homebrew , fzf
brew_fzf_install() {
# Check if arguments are provided
if [[ $# -eq 0 ]]; then
echo "Usage: brew_fzf_install <search_terms>"
echo "Example: brew_fzf_install python git"
return 1
fi
# Check if brew is installed
if ! command -v brew &> /dev/null; then
echo "Error: Homebrew is not installed or not in PATH"
return 1
fi
# Check if fzf is installed
if ! command -v fzf &> /dev/null; then
echo "Error: fzf is not installed. Install it with: brew install fzf"
return 1
fi
# Pass all arguments to brew search and pipe to fzf
local selected_package
selected_package=$(brew search "$@" | fzf \
--prompt="Select package to install: " \
--height=40% \
--border \
--preview='brew info {}' \
--preview-window=right:60%:wrap)
# Check if a package was selected
if [[ -n "$selected_package" ]]; then
echo "Installing: $selected_package"
brew install "$selected_package"
else
echo "No package selected. Installation cancelled."
return 1
fi
}
# Alias for easier usage
alias brewf='brew_fzf_install'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment