86542dcd8627d0e9a4b1acd8c01a9cdae4697698

Author
Maxime Brunet <32458727+maxbrunet@users.noreply.github.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

Add fzf plugin (#6910)

Diff

 1diff --git a/plugins/fzf/README.md b/plugins/fzf/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..b3a434347403fb210d507dec6a9a2466b7ec44b8
 4--- /dev/null
 5+++ b/plugins/fzf/README.md
 6@@ -0,0 +1,19 @@
 7+# fzf
 8+
 9+This plugin enables [junegunn's fzf](https://github.com/junegunn/fzf) fuzzy auto-completion and key bindings
10+
11+```zsh
12+# Set fzf installation directory path
13+export FZF_BASE=/path/to/fzf/install/dir
14+
15+# Uncomment the following line to disable fuzzy completion
16+# export DISABLE_FZF_AUTO_COMPLETION="true"
17+
18+# Uncomment the following line to disable key bindings (CTRL-T, CTRL-R, ALT-C)
19+# export DISABLE_FZF_KEY_BINDINGS="true"
20+
21+plugins=(
22+  ...
23+  fzf
24+)
25+```
26diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh
27new file mode 100644
28index 0000000000000000000000000000000000000000..b28b9799401ec6d88a2d068d5f06fd474c44b784
29--- /dev/null
30+++ b/plugins/fzf/fzf.plugin.zsh
31@@ -0,0 +1,50 @@
32+test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
33+
34+if [[ -z "${fzf_base}" ]]; then
35+  fzfdirs=(
36+    "${HOME}/.fzf"
37+    "/usr/local/opt/fzf"
38+    "/usr/share/fzf"
39+  )
40+  for dir in ${fzfdirs}; do
41+      if [[ -d "${dir}" ]]; then
42+          fzf_base="${dir}"
43+          break
44+      fi
45+  done
46+
47+  if [[ -z "${fzf_base}" ]]; then
48+      if (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
49+          if [[ -d "${dir}" ]]; then
50+              fzf_base="${dir}"
51+          fi
52+      fi
53+  fi
54+fi
55+
56+if [[ -n "${fzf_base}" ]]; then
57+
58+  # Setup fzf
59+  # ---------
60+  if [[ ! "$PATH" == *$fzf_base/bin* ]]; then
61+    export PATH="$PATH:$fzf_base/bin"
62+  fi
63+  
64+  # Auto-completion
65+  # ---------------
66+  if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
67+    [[ $- == *i* ]] && source "$fzf_base/shell/completion.zsh" 2> /dev/null
68+  fi
69+  
70+  # Key bindings
71+  # ------------
72+  if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
73+    source "$fzf_base/shell/key-bindings.zsh"
74+  fi
75+
76+else
77+  print "[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.\n"\
78+        "Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc" >&2
79+fi
80+
81+unset fzf_base