1 function fzf_setup_using_base_dir() {
2 local fzf_base fzf_shell fzfdirs dir
4 test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
6 if [[ -z "${fzf_base}" ]]; then
9 "${HOME}/.nix-profile/share/fzf"
10 "${XDG_DATA_HOME:-$HOME/.local/share}/fzf"
13 "/usr/local/share/examples/fzf"
15 for dir in ${fzfdirs}; do
16 if [[ -d "${dir}" ]]; then
22 if [[ -z "${fzf_base}" ]]; then
23 if (( ${+commands[fzf-share]} )) && dir="$(fzf-share)" && [[ -d "${dir}" ]]; then
25 elif (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
26 if [[ -d "${dir}" ]]; then
33 if [[ ! -d "${fzf_base}" ]]; then
37 # Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages
38 if [[ ! -d "${fzf_base}/shell" ]]; then
39 fzf_shell="${fzf_base}"
41 fzf_shell="${fzf_base}/shell"
44 # Setup fzf binary path
45 if (( ! ${+commands[fzf]} )) && [[ "$PATH" != *$fzf_base/bin* ]]; then
46 export PATH="$PATH:$fzf_base/bin"
50 if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
51 source "${fzf_shell}/completion.zsh" 2> /dev/null
55 if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
56 source "${fzf_shell}/key-bindings.zsh"
61 function fzf_setup_using_debian() {
62 if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then
63 # Either not a debian based distro, or no fzf installed
67 # NOTE: There is no need to configure PATH for debian package, all binaries
68 # are installed to /usr/bin by default
70 local completions key_bindings
74 # Support Termux package
75 completions="${PREFIX}/share/fzf/completion.zsh"
76 key_bindings="${PREFIX}/share/fzf/key-bindings.zsh"
79 # Determine completion file path: first bullseye/sid, then buster/stretch
80 completions="/usr/share/doc/fzf/examples/completion.zsh"
81 [[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf"
82 key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
87 if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
88 source $completions 2> /dev/null
92 if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
99 function fzf_setup_using_opensuse() {
100 # OpenSUSE installs fzf in /usr/bin/fzf
101 # If the command is not found, the package isn't installed
102 (( $+commands[fzf] )) || return 1
104 # The fzf-zsh-completion package installs the auto-completion in
105 local completions="/usr/share/zsh/site-functions/_fzf"
106 # The fzf-zsh-completion package installs the key-bindings file in
107 local key_bindings="/etc/zsh_completion.d/fzf-key-bindings"
109 # If these are not found: (1) maybe we're not on OpenSUSE, or
110 # (2) maybe the fzf-zsh-completion package isn't installed.
111 if [[ ! -f "$completions" || ! -f "$key_bindings" ]]; then
116 if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
117 source "$completions" 2>/dev/null
121 if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
122 source "$key_bindings" 2>/dev/null
128 function fzf_setup_using_openbsd() {
129 # openBSD installs fzf in /usr/local/bin/fzf
130 if [[ "$OSTYPE" != openbsd* ]] || (( ! $+commands[fzf] )); then
134 # The fzf package installs the auto-completion in
135 local completions="/usr/local/share/zsh/site-functions/_fzf_completion"
136 # The fzf package installs the key-bindings file in
137 local key_bindings="/usr/local/share/zsh/site-functions/_fzf_key_bindings"
140 if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
141 source "$completions" 2>/dev/null
145 if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
146 source "$key_bindings" 2>/dev/null
152 function fzf_setup_using_cygwin() {
153 # Cygwin installs fzf in /usr/local/bin/fzf
154 if [[ "$OSTYPE" != cygwin* ]] || (( ! $+commands[fzf] )); then
158 # The fzf-zsh-completion package installs the auto-completion in
159 local completions="/etc/profile.d/fzf-completion.zsh"
160 # The fzf-zsh package installs the key-bindings file in
161 local key_bindings="/etc/profile.d/fzf.zsh"
164 if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
165 source "$completions" 2>/dev/null
169 if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
170 source "$key_bindings" 2>/dev/null
176 function fzf_setup_using_macports() {
177 # If the command is not found, the package isn't installed
178 (( $+commands[fzf] )) || return 1
180 # The fzf-zsh-completion package installs the auto-completion in
181 local completions="/opt/local/share/zsh/site-functions/fzf"
182 # The fzf-zsh-completion package installs the key-bindings file in
183 local key_bindings="/opt/local/share/fzf/shell/key-bindings.zsh"
185 if [[ ! -f "$completions" || ! -f "$key_bindings" ]]; then
190 if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
191 source "$completions" 2>/dev/null
195 if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
196 source "$key_bindings" 2>/dev/null
202 # Indicate to user that fzf installation not found if nothing worked
203 function fzf_setup_error() {
205 [oh-my-zsh] fzf plugin: Cannot find fzf installation directory.
206 Please add `export FZF_BASE=/path/to/fzf/install/dir` to your .zshrc
210 fzf_setup_using_openbsd \
211 || fzf_setup_using_debian \
212 || fzf_setup_using_opensuse \
213 || fzf_setup_using_cygwin \
214 || fzf_setup_using_macports \
215 || fzf_setup_using_base_dir \
218 unset -f -m 'fzf_setup_*'
220 if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
221 if (( $+commands[fd] )); then
222 export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
223 elif (( $+commands[rg] )); then
224 export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git/*"'
225 elif (( $+commands[ag] )); then
226 export FZF_DEFAULT_COMMAND='ag -l --hidden -g "" --ignore .git'