Skip to content

Commit 894d146

Browse files
authored
Merge pull request #129 from unixorn/fix-128-broken-alias-checks
Fix broken alias checks
2 parents 0320037 + 8cbb1ba commit 894d146

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

fzf-settings.zsh

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

7-
if (( $+commands[brew] )); then
7+
function _fzf_settings_has() {
8+
which "$@" > /dev/null 2>&1
9+
}
10+
11+
if _fzf_settings_has brew; then
812
# If fzf was installed via brew, use the brew paths
913
if [[ -x "$(brew --prefix)/bin/fzf" ]]; then
1014
if [[ -f "$(brew --prefix fzf)/shell/completion.zsh" ]]; then
@@ -27,3 +31,6 @@ fi
2731
if [[ -f "${FZF_PATH}/shell/key-bindings.zsh" ]]; then
2832
source "${FZF_PATH}/shell/key-bindings.zsh"
2933
fi
34+
35+
# Cleanup internal functions
36+
unset -f _fzf_settings_has

fzf-zsh-plugin.plugin.zsh

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ 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+
2832
function _fzf_debugOut() {
2933
if [[ -n "$DEBUG" ]]; then
3034
echo "$@"
@@ -45,7 +49,7 @@ fi
4549
unset 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'"
@@ -102,11 +106,11 @@ fi
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[@]}")
146150
fi
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")
166170
fi
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
@@ -199,4 +203,5 @@ fi
199203

200204
# Cleanup internal functions
201205
unset -f _fzf_debugOut
206+
unset -f _fzf_has
202207
unset -f _fzf_preview

0 commit comments

Comments
 (0)