Skip to content

Commit 0320037

Browse files
authored
Merge pull request #127 from unixorn/another-fix-for-125
Replace `_fzf_has()`
2 parents 1a30186 + 5257af4 commit 0320037

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

fzf-settings.zsh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ if [[ ! "$PATH" == *${FZF_PATH}/bin* ]]; then
44
export PATH="$PATH:${FZF_PATH}/bin"
55
fi
66

7-
function _fzf_has() {
8-
which "$@" > /dev/null 2>&1
9-
}
10-
11-
if _fzf_has brew; then
7+
if (( $+commands[brew] )); then
128
# If fzf was installed via brew, use the brew paths
139
if [[ -x "$(brew --prefix)/bin/fzf" ]]; then
1410
if [[ -f "$(brew --prefix fzf)/shell/completion.zsh" ]]; then

fzf-zsh-plugin.plugin.zsh

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ if [[ -d "$FZF_COMPLETIONS_D" ]]; then
2525
fi
2626
unset FZF_COMPLETIONS_D
2727

28-
function _fzf_has() {
29-
which "$@" > /dev/null 2>&1
30-
}
31-
3228
function _fzf_debugOut() {
3329
if [[ -n "$DEBUG" ]]; then
3430
echo "$@"
@@ -49,7 +45,7 @@ fi
4945
unset xdg_path
5046

5147
# Install fzf into ~ if it hasn't already been installed.
52-
if ! _fzf_has fzf; then
48+
if ! (( $+commands[fzf] )); then
5349
if [[ ! -d $FZF_PATH ]]; then
5450
git clone --depth 1 https://github.com/junegunn/fzf.git $FZF_PATH
5551
$FZF_PATH/install --bin
@@ -75,14 +71,14 @@ if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
7571
export FZF_DEFAULT_COMMAND='find . -type f -not \( -path "*/.git/*" -o -path "./node_modules/*" \)'
7672
export FZF_ALT_C_COMMAND='find . -type d ( -path .git -o -path node_modules ) -prune'
7773

78-
if _fzf_has rg; then
74+
if (( $+commands[rg] )); then
7975
# rg is faster than find, so use it instead.
8076
export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --glob "!{.git,node_modules}/**"'
8177
fi
8278

8379
# If fd command is installed, use it instead of find
84-
_fzf_has 'fd' && _fd_cmd="fd"
85-
_fzf_has 'fdfind' && _fd_cmd="fdfind"
80+
(( $+commands[fd] )) && _fd_cmd="fd"
81+
(( $+commands[fdfind] )) && _fd_cmd="fdfind"
8682
if [[ -n "$_fd_cmd" ]]; then
8783
# Show hidden, and exclude .git and the pigsty node_modules files
8884
export FZF_DEFAULT_COMMAND="$_fd_cmd --hidden --follow --exclude '.git' --exclude 'node_modules'"
@@ -106,11 +102,11 @@ fi
106102
_fzf_preview() {
107103
_fzf_preview_pager='cat'
108104
foolproofPreview='cat {}'
109-
if _fzf_has bat; then
105+
if (( $+commands[bat] )); then
110106
_fzf_preview_pager='bat'
111107
foolproofPreview='([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2>/dev/null | head -n 200'
112108
fi
113-
if _fzf_has batcat; then
109+
if (( $+commands[batcat] )); then
114110
_fzf_preview_pager='batcat'
115111
foolproofPreview='([[ -f {} ]] && (batcat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2>/dev/null | head -n 200'
116112
fi
@@ -142,14 +138,14 @@ if [[ -z "$FZF_DEFAULT_OPTS" ]]; then
142138
"--bind 'ctrl-e:execute(vim {+} >/dev/tty)'"
143139
"--bind 'ctrl-v:execute(code {+})'"
144140
)
145-
if _fzf_has pbcopy; then
141+
if (( $+commands[pbcopy] )); then
146142
# On macOS, make ^Y yank the selection to the system clipboard. On Linux you can alias pbcopy to `xclip -selection clipboard` or corresponding tool.
147143
fzf_default_opts+=("--bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'")
148144
fi
149145
export FZF_DEFAULT_OPTS=$(printf '%s\n' "${fzf_default_opts[@]}")
150146
fi
151147

152-
if _fzf_has tree; then
148+
if (( $+commands[tree] )); then
153149
function fzf-change-directory() {
154150
local directory=$(
155151
fd --type d | \
@@ -169,7 +165,7 @@ if [[ -d $FZF_PATH/man ]]; then
169165
manpath+=(":$FZF_PATH/man")
170166
fi
171167

172-
if _fzf_has z && ! _fzf_has zoxide; then
168+
if (( $+commands[z] )) && ! (( $+commands[zoxide] )); then
173169
unalias z 2> /dev/null
174170
_fzf_z="_z"
175171
(( ${+functions[zshz]} )) && { _fzf_z="zshz"; compdef _zshz z; }
@@ -190,8 +186,8 @@ function cdf() {
190186
file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir"
191187
}
192188

193-
if _fzf_has pbcopy; then
194-
if _fzf_has ghead; then
189+
if (( $+commands[pbcopy] )); then
190+
if (( $+commands[ghead] )); then
195191
function falias {
196192
# Search alias by key or values
197193
local out
@@ -203,5 +199,4 @@ fi
203199

204200
# Cleanup internal functions
205201
unset -f _fzf_debugOut
206-
unset -f _fzf_has
207202
unset -f _fzf_preview

0 commit comments

Comments
 (0)