Unverified Commit bb6ae70b authored by Marc Cornellà's avatar Marc Cornellà Committed by GitHub
Browse files

fzf: add support for debian packages (#8001)

parents 51f0eaad 0565251c
test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}" function setup_using_base_dir() {
# Declare all variables local not no mess with outside env in any way
if [[ -z "${fzf_base}" ]]; then local fzf_base
fzfdirs=( local fzf_shell
"${HOME}/.fzf" local fzfdirs
"/usr/local/opt/fzf" local dir
"/usr/share/fzf"
) test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
for dir in ${fzfdirs}; do
if [[ -d "${dir}" ]]; then if [[ -z "${fzf_base}" ]]; then
fzf_base="${dir}" fzfdirs=(
break "${HOME}/.fzf"
fi "/usr/local/opt/fzf"
done "/usr/share/fzf"
)
if [[ -z "${fzf_base}" ]]; then for dir in ${fzfdirs}; do
if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then if [[ -d "${dir}" ]]; then
if [[ -d "${dir}" ]]; then fzf_base="${dir}"
fzf_base="${dir}" break
fi fi
fi done
fi
fi if [[ -z "${fzf_base}" ]]; then
if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
if [[ -n "${fzf_base}" ]]; then if [[ -d "${dir}" ]]; then
fzf_base="${dir}"
# Fix fzf shell directory for Archlinux package fi
if [[ ! -d "${fzf_base}/shell" ]] && [[ -f /etc/arch-release ]]; then fi
fzf_shell="${fzf_base}" fi
else fi
fzf_shell="${fzf_base}/shell"
fi if [[ -d "${fzf_base}" ]]; then
# Fix fzf shell directory for Archlinux package
# Setup fzf if [[ ! -d "${fzf_base}/shell" ]] && [[ -f /etc/arch-release ]]; then
# --------- fzf_shell="${fzf_base}"
if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then else
export PATH="$PATH:$fzf_base/bin" fzf_shell="${fzf_base}/shell"
fi fi
# Auto-completion # Setup fzf binary path
# --------------- if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then
if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then export PATH="$PATH:$fzf_base/bin"
[[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null fi
fi
# Auto-completion
# Key bindings if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
# ------------ [[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null
if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then fi
source "${fzf_shell}/key-bindings.zsh"
fi # Key bindings
if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
else source "${fzf_shell}/key-bindings.zsh"
print "[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.\n"\ fi
"Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc" >&2 else
fi return 1
fi
unset fzf_base fzf_shell dir fzfdirs }
function setup_using_debian_package() {
dpkg -s fzf &> /dev/null
if (( $? )); then
# Either not a debian based distro, or no fzf installed. In any case skip ahead
return 1
fi
# NOTE: There is no need to configure PATH for debian package, all binaries
# are installed to /usr/bin by default
local completions="/usr/share/zsh/vendor-completions/_fzf"
local key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
# Auto-completion
if [[ $- == *i* ]] && [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
source $completions 2> /dev/null
fi
# Key bindings
if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
source $key_bindings
fi
return 0
}
function indicate_error() {
print "[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.\n"\
"Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc" >&2
}
# Check for debian package first, because it easy to short cut
# Indicate to user that fzf installation not found if nothing worked
setup_using_debian_package || setup_using_base_dir || indicate_error
unset -f setup_using_debian_package setup_using_base_dir indicate_error
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment