-
Notifications
You must be signed in to change notification settings - Fork 3
/
fzf-brew.plugin.zsh
76 lines (61 loc) · 2.42 KB
/
fzf-brew.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env zsh
if ! (( $+commands[brew] )); then
echo 'brew command not found: please install via https://brew.sh/'
return
fi
if ! (( $+commands[fzf] )); then
echo 'fzf command not found: please install via "brew install fzf"'
return
fi
FB_FORMULA_PREVIEW='HOMEBREW_COLOR=true brew info {}'
FB_FORMULA_BIND="ctrl-space:execute-silent(brew home {})"
FB_CASK_PREVIEW='HOMEBREW_COLOR=true brew info --cask {}'
FB_CASK_BIND="ctrl-space:execute-silent(brew home --cask {})"
# completion bindings
function _fzf_complete_brew() {
local arguments=$@
if [[ $arguments == 'brew install --cask'* ]]; then
_fzf_complete -m --preview $FB_FORMULA_PREVIEW --bind $FB_FORMULA_BIND -- "$@" < <(brew casks)
elif [[ $arguments == 'brew uninstall --cask'* ]]; then
_fzf_complete -m --preview $FB_FORMULA_PREVIEW --bind $FB_FORMULA_BIND -- "$@" < <(brew list --cask)
elif [[ $arguments == 'brew install'* ]]; then
_fzf_complete -m --preview $FB_FORMULA_PREVIEW --bind $FB_FORMULA_BIND -- "$@" < <(brew formulae)
elif [[ $arguments == 'brew uninstall'* ]]; then
_fzf_complete -m --preview $FB_FORMULA_PREVIEW --bind $FB_FORMULA_BIND -- "$@" < <(brew leaves)
else
eval "zle ${fzf_default_completion:-expand-or-complete}"
fi
}
# functions
function fuzzy_brew_install() {
local inst=$(brew formulae | fzf --query="$1" -m --preview $FB_FORMULA_PREVIEW --bind $FB_FORMULA_BIND)
if [[ $inst ]]; then
for prog in $(echo $inst); do; brew install $prog; done;
fi
}
function fuzzy_brew_uninstall() {
local uninst=$(brew leaves | fzf --query="$1" -m --preview $FB_FORMULA_PREVIEW --bind $FB_FORMULA_BIND)
if [[ $uninst ]]; then
for prog in $(echo $uninst);
do; brew uninstall $prog; done;
fi
}
function fuzzy_cask_install() {
local inst=$(brew casks | fzf --query="$1" -m --preview $FB_CASK_PREVIEW --bind $FB_CASK_BIND)
if [[ $inst ]]; then
for prog in $(echo $inst); do; brew install --cask $prog; done;
fi
}
function fuzzy_cask_uninstall() {
local inst=$(brew list --cask | fzf --query="$1" -m --preview $FB_CASK_PREVIEW --bind $FB_CASK_BIND)
if [[ $inst ]]; then
for prog in $(echo $inst); do; brew uninstall --cask $prog; done;
fi
}
function __setup_fzf_brew() {
alias fbi=fuzzy_brew_install
alias fbui=fuzzy_brew_uninstall
alias fci=fuzzy_cask_install
alias fcui=fuzzy_cask_uninstall
}
__setup_fzf_brew