mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-17 07:43:39 -05:00
Add more complete options for brew
64
Examples.md
64
Examples.md
@@ -1234,6 +1234,70 @@ bcp() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Search and Install a formula or cask (enter to install)
|
||||||
|
# needs zsh, jq, curl
|
||||||
|
brewi() {
|
||||||
|
brewi_fetch() {
|
||||||
|
local url="$1"
|
||||||
|
local cache_key="$2"
|
||||||
|
local cache_folder="$HOME/.brewi.cache"
|
||||||
|
local file="$cache_folder/$cache_key"
|
||||||
|
if [[ "$file"(Nm-14) != "$file" ]]; then
|
||||||
|
2>& echo "Older than 2 weeks, cache reloading..."
|
||||||
|
mkdir -p $cache_folder
|
||||||
|
curl -s "$url" > "$file"
|
||||||
|
fi
|
||||||
|
echo "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
local formula_file=$(brewi_fetch 'https://formulae.brew.sh/api/formula.json' 'formula')
|
||||||
|
local cask_file=$(brewi_fetch 'https://formulae.brew.sh/api/cask.json' 'cask')
|
||||||
|
|
||||||
|
{
|
||||||
|
jq --raw-output '.[] | .name' $formula_file
|
||||||
|
jq --raw-output '.[] | .token + " (cask)"' $cask_file
|
||||||
|
} | sort | \
|
||||||
|
fzf --reverse \
|
||||||
|
--prompt="Brew Install " \
|
||||||
|
--bind="enter:execute(
|
||||||
|
if [[ '{2}' == '(cask)' ]]; then
|
||||||
|
brew install --cask {1}
|
||||||
|
else
|
||||||
|
brew install {1}
|
||||||
|
fi
|
||||||
|
echo $'\n\e[34mPress any key to continue...' && read -rsk 1)+first+clear-query" \
|
||||||
|
--preview='brew info {1} | bat --color=always --language=Markdown --style=plain' \
|
||||||
|
--preview-window='bottom,wrap,<13(right)'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Uninstall a formula or cask (on enter)
|
||||||
|
# needs zsh, jq
|
||||||
|
brewr() {
|
||||||
|
brew info --json=v2 --installed |
|
||||||
|
jq --raw-output '
|
||||||
|
(.formulae[] | .name),
|
||||||
|
(.casks[] | .token + " (cask)")
|
||||||
|
' | \
|
||||||
|
sort | \
|
||||||
|
fzf --reverse \
|
||||||
|
--prompt="Brew Remove " \
|
||||||
|
--bind="enter:execute(
|
||||||
|
if [[ '{2}' == '(cask)' ]]; then
|
||||||
|
brew uninstall --cask {1}
|
||||||
|
else
|
||||||
|
brew uninstall {1}
|
||||||
|
fi
|
||||||
|
echo $'\n\e[34mPress any key to continue...' && read -rsk 1 && printf '\n'
|
||||||
|
)+first+clear-query" \
|
||||||
|
--preview='brew info {1} | bat --color=always --language=Markdown --style=plain' \
|
||||||
|
--preview-window='bottom,wrap,<13(right)'
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Homebrew Cask
|
### Homebrew Cask
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user