fzf.plugin.zsh 1.38 KB
Newer Older
Maxime Brunet's avatar
Maxime Brunet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"

if [[ -z "${fzf_base}" ]]; then
  fzfdirs=(
    "${HOME}/.fzf"
    "/usr/local/opt/fzf"
    "/usr/share/fzf"
  )
  for dir in ${fzfdirs}; do
      if [[ -d "${dir}" ]]; then
          fzf_base="${dir}"
          break
      fi
  done

  if [[ -z "${fzf_base}" ]]; then
      if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
          if [[ -d "${dir}" ]]; then
              fzf_base="${dir}"
          fi
      fi
  fi
fi

if [[ -n "${fzf_base}" ]]; then

27
28
29
30
31
32
33
  # Fix fzf shell directory for Archlinux package
  if [[ ! -d "${fzf_base}/shell" ]] && [[ -f /etc/arch-release ]]; then
    fzf_shell="${fzf_base}"
  else
    fzf_shell="${fzf_base}/shell"
  fi

Maxime Brunet's avatar
Maxime Brunet committed
34
35
  # Setup fzf
  # ---------
36
  if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then
Maxime Brunet's avatar
Maxime Brunet committed
37
38
39
40
41
42
    export PATH="$PATH:$fzf_base/bin"
  fi
  
  # Auto-completion
  # ---------------
  if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
43
    [[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null
Maxime Brunet's avatar
Maxime Brunet committed
44
45
46
47
48
  fi
  
  # Key bindings
  # ------------
  if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
49
    source "${fzf_shell}/key-bindings.zsh"
Maxime Brunet's avatar
Maxime Brunet committed
50
51
52
53
54
55
56
  fi

else
  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
fi

57
unset fzf_base fzf_shell dir fzfdirs