fzf.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
  2. if [[ -z "${fzf_base}" ]]; then
  3. fzfdirs=(
  4. "${HOME}/.fzf"
  5. "/usr/local/opt/fzf"
  6. "/usr/share/fzf"
  7. )
  8. for dir in ${fzfdirs}; do
  9. if [[ -d "${dir}" ]]; then
  10. fzf_base="${dir}"
  11. break
  12. fi
  13. done
  14. if [[ -z "${fzf_base}" ]]; then
  15. if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
  16. if [[ -d "${dir}" ]]; then
  17. fzf_base="${dir}"
  18. fi
  19. fi
  20. fi
  21. fi
  22. if [[ -n "${fzf_base}" ]]; then
  23. # Fix fzf shell directory for Archlinux package
  24. if [[ ! -d "${fzf_base}/shell" ]] && [[ -f /etc/arch-release ]]; then
  25. fzf_shell="${fzf_base}"
  26. else
  27. fzf_shell="${fzf_base}/shell"
  28. fi
  29. # Setup fzf
  30. # ---------
  31. if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then
  32. export PATH="$PATH:$fzf_base/bin"
  33. fi
  34. # Auto-completion
  35. # ---------------
  36. if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
  37. [[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null
  38. fi
  39. # Key bindings
  40. # ------------
  41. if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
  42. source "${fzf_shell}/key-bindings.zsh"
  43. fi
  44. else
  45. print "[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.\n"\
  46. "Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc" >&2
  47. fi
  48. unset fzf_base fzf_shell dir fzfdirs