@@ -25,6 +25,10 @@ if [[ -d "$FZF_COMPLETIONS_D" ]]; then
2525fi
2626unset FZF_COMPLETIONS_D
2727
28+ function _fzf_has() {
29+ which " $@ " > /dev/null 2>&1
30+ }
31+
2832function _fzf_debugOut() {
2933 if [[ -n " $DEBUG " ]]; then
3034 echo " $@ "
4549unset xdg_path
4650
4751# Install fzf into ~ if it hasn't already been installed.
48- if ! (( $ + commands[ fzf] )) ; then
52+ if ! _fzf_has fzf; then
4953 if [[ ! -d $FZF_PATH ]]; then
5054 git clone --depth 1 https://github.com/junegunn/fzf.git $FZF_PATH
5155 $FZF_PATH /install --bin
@@ -71,14 +75,14 @@ if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
7175 export FZF_DEFAULT_COMMAND=' find . -type f -not \( -path "*/.git/*" -o -path "./node_modules/*" \)'
7276 export FZF_ALT_C_COMMAND=' find . -type d ( -path .git -o -path node_modules ) -prune'
7377
74- if (( $ + commands[rg] )) ; then
78+ if _fzf_has rg ; then
7579 # rg is faster than find, so use it instead.
7680 export FZF_DEFAULT_COMMAND=' rg --files --hidden --follow --glob "!{.git,node_modules}/**"'
7781 fi
7882
7983 # If fd command is installed, use it instead of find
80- (( $ + commands[fd] )) && _fd_cmd=" fd"
81- (( $ + commands[ fdfind] )) && _fd_cmd=" fdfind"
84+ _fzf_has ' fd ' && _fd_cmd=" fd"
85+ _fzf_has ' fdfind' && _fd_cmd=" fdfind"
8286 if [[ -n " $_fd_cmd " ]]; then
8387 # Show hidden, and exclude .git and the pigsty node_modules files
8488 export FZF_DEFAULT_COMMAND=" $_fd_cmd --hidden --follow --exclude '.git' --exclude 'node_modules'"
102106_fzf_preview () {
103107 _fzf_preview_pager=' cat'
104108 foolproofPreview=' cat {}'
105- if (( $ + commands[ bat] )) ; then
109+ if _fzf_has bat; then
106110 _fzf_preview_pager=' bat'
107111 foolproofPreview=' ([[ -f {} ]] && (bat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2>/dev/null | head -n 200'
108112 fi
109- if (( $ + commands[ batcat] )) ; then
113+ if _fzf_has batcat; then
110114 _fzf_preview_pager=' batcat'
111115 foolproofPreview=' ([[ -f {} ]] && (batcat --style=numbers --color=always {} || cat {})) || ([[ -d {} ]] && (tree -C {} | less)) || echo {} 2>/dev/null | head -n 200'
112116 fi
@@ -138,14 +142,14 @@ if [[ -z "$FZF_DEFAULT_OPTS" ]]; then
138142 " --bind 'ctrl-e:execute(vim {+} >/dev/tty)'"
139143 " --bind 'ctrl-v:execute(code {+})'"
140144 )
141- if (( $ + commands[ pbcopy] )) ; then
145+ if _fzf_has pbcopy; then
142146 # On macOS, make ^Y yank the selection to the system clipboard. On Linux you can alias pbcopy to `xclip -selection clipboard` or corresponding tool.
143147 fzf_default_opts+=(" --bind 'ctrl-y:execute-silent(echo {+} | pbcopy)'" )
144148 fi
145149 export FZF_DEFAULT_OPTS=$( printf ' %s\n' " ${fzf_default_opts[@]} " )
146150fi
147151
148- if (( $ + commands[ tree] )) ; then
152+ if _fzf_has tree; then
149153 function fzf-change-directory() {
150154 local directory=$(
151155 fd --type d | \
@@ -165,7 +169,7 @@ if [[ -d $FZF_PATH/man ]]; then
165169 manpath+=(" :$FZF_PATH /man" )
166170fi
167171
168- if (( $ + commands[z] )) && ! (( $ + commands[ zoxide] )) ; then
172+ if _fzf_has z && ! _fzf_has zoxide; then
169173 unalias z 2> /dev/null
170174 _fzf_z=" _z"
171175 (( ${+functions[zshz]} )) && { _fzf_z=" zshz" ; compdef _zshz z; }
@@ -186,8 +190,8 @@ function cdf() {
186190 file=$( fzf +m -q " $1 " ) && dir=$( dirname " $file " ) && cd " $dir "
187191}
188192
189- if (( $ + commands[ pbcopy] )) ; then
190- if (( $ + commands[ ghead] )) ; then
193+ if _fzf_has pbcopy; then
194+ if _fzf_has ghead; then
191195 function falias {
192196 # Search alias by key or values
193197 local out
199203
200204# Cleanup internal functions
201205unset -f _fzf_debugOut
206+ unset -f _fzf_has
202207unset -f _fzf_preview
0 commit comments