2019-07-14 23:40:28 +02:00
|
|
|
function setup_using_base_dir() {
|
2020-10-20 23:48:59 +02:00
|
|
|
local fzf_base fzf_shell fzfdirs dir
|
2019-07-14 23:40:28 +02:00
|
|
|
|
|
|
|
test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
|
|
|
|
|
|
|
|
if [[ -z "${fzf_base}" ]]; then
|
|
|
|
fzfdirs=(
|
|
|
|
"${HOME}/.fzf"
|
2020-02-13 18:57:52 +01:00
|
|
|
"${HOME}/.nix-profile/share/fzf"
|
2021-04-23 20:28:42 +02:00
|
|
|
"${XDG_DATA_HOME:-$HOME/.local/share}/fzf"
|
2019-07-14 23:40:28 +02:00
|
|
|
"/usr/local/opt/fzf"
|
|
|
|
"/usr/share/fzf"
|
2019-12-19 10:50:20 +01:00
|
|
|
"/usr/local/share/examples/fzf"
|
2019-07-14 23:40:28 +02:00
|
|
|
)
|
|
|
|
for dir in ${fzfdirs}; do
|
|
|
|
if [[ -d "${dir}" ]]; then
|
|
|
|
fzf_base="${dir}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "${fzf_base}" ]]; then
|
2021-10-27 11:40:09 +02:00
|
|
|
if (( ${+commands[fzf-share]} )) && dir="$(fzf-share)" && [[ -d "${dir}" ]]; then
|
|
|
|
fzf_base="${dir}"
|
|
|
|
elif (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
|
2019-07-14 23:40:28 +02:00
|
|
|
if [[ -d "${dir}" ]]; then
|
|
|
|
fzf_base="${dir}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-10-20 23:48:59 +02:00
|
|
|
if [[ ! -d "${fzf_base}" ]]; then
|
|
|
|
return 1
|
|
|
|
fi
|
2019-07-14 23:40:28 +02:00
|
|
|
|
2020-10-20 23:48:59 +02:00
|
|
|
# Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages
|
|
|
|
if [[ ! -d "${fzf_base}/shell" ]]; then
|
|
|
|
fzf_shell="${fzf_base}"
|
|
|
|
else
|
|
|
|
fzf_shell="${fzf_base}/shell"
|
|
|
|
fi
|
2019-07-14 23:40:28 +02:00
|
|
|
|
2020-10-20 23:48:59 +02:00
|
|
|
# Setup fzf binary path
|
|
|
|
if (( ! ${+commands[fzf]} )) && [[ "$PATH" != *$fzf_base/bin* ]]; then
|
|
|
|
export PATH="$PATH:$fzf_base/bin"
|
|
|
|
fi
|
2019-07-14 23:40:28 +02:00
|
|
|
|
2020-10-20 23:48:59 +02:00
|
|
|
# Auto-completion
|
|
|
|
if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
|
|
|
|
source "${fzf_shell}/completion.zsh" 2> /dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Key bindings
|
|
|
|
if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
|
|
|
|
source "${fzf_shell}/key-bindings.zsh"
|
2019-07-14 23:40:28 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setup_using_debian_package() {
|
2020-10-20 23:48:59 +02:00
|
|
|
if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then
|
|
|
|
# Either not a debian based distro, or no fzf installed
|
2019-07-14 23:40:28 +02:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# NOTE: There is no need to configure PATH for debian package, all binaries
|
|
|
|
# are installed to /usr/bin by default
|
|
|
|
|
2021-03-15 22:34:47 +01:00
|
|
|
local completions key_bindings
|
|
|
|
|
|
|
|
case $PREFIX in
|
|
|
|
*com.termux*)
|
|
|
|
# Support Termux package
|
|
|
|
completions="${PREFIX}/share/fzf/completion.zsh"
|
|
|
|
key_bindings="${PREFIX}/share/fzf/key-bindings.zsh"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# Determine completion file path: first bullseye/sid, then buster/stretch
|
|
|
|
completions="/usr/share/doc/fzf/examples/completion.zsh"
|
|
|
|
[[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf"
|
|
|
|
key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
|
|
|
|
;;
|
|
|
|
esac
|
2019-07-14 23:40:28 +02:00
|
|
|
|
|
|
|
# Auto-completion
|
2020-10-20 23:48:59 +02:00
|
|
|
if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
|
|
|
|
source $completions 2> /dev/null
|
2019-07-14 23:40:28 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Key bindings
|
|
|
|
if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
|
|
|
|
source $key_bindings
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-10-20 23:48:59 +02:00
|
|
|
function setup_using_opensuse_package() {
|
|
|
|
# OpenSUSE installs fzf in /usr/bin/fzf
|
|
|
|
# If the command is not found, the package isn't installed
|
|
|
|
(( $+commands[fzf] )) || return 1
|
|
|
|
|
|
|
|
# The fzf-zsh-completion package installs the auto-completion in
|
|
|
|
local completions="/usr/share/zsh/site-functions/_fzf"
|
|
|
|
# The fzf-zsh-completion package installs the key-bindings file in
|
|
|
|
local key_bindings="/etc/zsh_completion.d/fzf-key-bindings"
|
|
|
|
|
|
|
|
# If these are not found: (1) maybe we're not on OpenSUSE, or
|
|
|
|
# (2) maybe the fzf-zsh-completion package isn't installed.
|
|
|
|
if [[ ! -f "$completions" || ! -f "$key_bindings" ]]; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Auto-completion
|
|
|
|
if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
|
|
|
|
source "$completions" 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Key bindings
|
|
|
|
if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
|
|
|
|
source "$key_bindings" 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup_using_openbsd_package() {
|
|
|
|
# openBSD installs fzf in /usr/local/bin/fzf
|
|
|
|
if [[ "$OSTYPE" != openbsd* ]] || (( ! $+commands[fzf] )); then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# The fzf package installs the auto-completion in
|
|
|
|
local completions="/usr/local/share/zsh/site-functions/_fzf_completion"
|
|
|
|
# The fzf package installs the key-bindings file in
|
|
|
|
local key_bindings="/usr/local/share/zsh/site-functions/_fzf_key_bindings"
|
|
|
|
|
|
|
|
# Auto-completion
|
|
|
|
if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
|
|
|
|
source "$completions" 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Key bindings
|
|
|
|
if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
|
|
|
|
source "$key_bindings" 2>/dev/null
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2019-07-14 23:40:28 +02:00
|
|
|
function indicate_error() {
|
2020-10-20 23:48:59 +02:00
|
|
|
cat >&2 <<EOF
|
|
|
|
[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.
|
|
|
|
Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc
|
|
|
|
EOF
|
2019-07-14 23:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Indicate to user that fzf installation not found if nothing worked
|
2020-10-20 23:48:59 +02:00
|
|
|
setup_using_openbsd_package \
|
|
|
|
|| setup_using_debian_package \
|
|
|
|
|| setup_using_opensuse_package \
|
|
|
|
|| setup_using_base_dir \
|
|
|
|
|| indicate_error
|
2019-07-17 01:43:00 +02:00
|
|
|
|
2020-10-20 23:48:59 +02:00
|
|
|
unset -f setup_using_opensuse_package setup_using_debian_package setup_using_base_dir indicate_error
|
2020-09-04 22:13:45 +02:00
|
|
|
|
|
|
|
if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
|
|
|
|
if (( $+commands[rg] )); then
|
2020-11-09 12:09:10 +01:00
|
|
|
export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git/*"'
|
2020-09-04 22:13:45 +02:00
|
|
|
elif (( $+commands[fd] )); then
|
|
|
|
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
|
|
|
|
elif (( $+commands[ag] )); then
|
2020-11-09 12:09:10 +01:00
|
|
|
export FZF_DEFAULT_COMMAND='ag -l --hidden -g "" --ignore .git'
|
2020-09-04 22:13:45 +02:00
|
|
|
fi
|
|
|
|
fi
|