From 86542dcd8627d0e9a4b1acd8c01a9cdae4697698 Mon Sep 17 00:00:00 2001 From: Maxime Brunet <32458727+maxbrunet@users.noreply.github.com> Date: Tue, 4 Sep 2018 16:25:45 -0400 Subject: Add fzf plugin (#6910) --- plugins/fzf/README.md | 19 ++++++++++++++++++ plugins/fzf/fzf.plugin.zsh | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 plugins/fzf/README.md create mode 100644 plugins/fzf/fzf.plugin.zsh (limited to 'plugins/fzf') diff --git a/plugins/fzf/README.md b/plugins/fzf/README.md new file mode 100644 index 000000000..b3a434347 --- /dev/null +++ b/plugins/fzf/README.md @@ -0,0 +1,19 @@ +# fzf + +This plugin enables [junegunn's fzf](https://github.com/junegunn/fzf) fuzzy auto-completion and key bindings + +```zsh +# Set fzf installation directory path +export FZF_BASE=/path/to/fzf/install/dir + +# Uncomment the following line to disable fuzzy completion +# export DISABLE_FZF_AUTO_COMPLETION="true" + +# Uncomment the following line to disable key bindings (CTRL-T, CTRL-R, ALT-C) +# export DISABLE_FZF_KEY_BINDINGS="true" + +plugins=( + ... + fzf +) +``` diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh new file mode 100644 index 000000000..b28b97994 --- /dev/null +++ b/plugins/fzf/fzf.plugin.zsh @@ -0,0 +1,50 @@ +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 + + # Setup fzf + # --------- + if [[ ! "$PATH" == *$fzf_base/bin* ]]; then + export PATH="$PATH:$fzf_base/bin" + fi + + # Auto-completion + # --------------- + if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then + [[ $- == *i* ]] && source "$fzf_base/shell/completion.zsh" 2> /dev/null + fi + + # Key bindings + # ------------ + if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then + source "$fzf_base/shell/key-bindings.zsh" + 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 + +unset fzf_base -- cgit v1.2.3-70-g09d2 From bb908495deae22314c3355235133063087698796 Mon Sep 17 00:00:00 2001 From: Maxime Brunet <32458727+maxbrunet@users.noreply.github.com> Date: Sat, 8 Sep 2018 09:31:13 -0400 Subject: fzf: Fix shell directory for archlinux package (#7119) * fzf: Fix shell directory for archlinux package * fzf: Don't clutter PATH if fzf already available * brew has it available via symlink in /usr/local/bin * Fedora and Arch packages have it place in /usr/bin * fzf: Fix archlinux guess by using release file * fzf: unset leftover variables --- plugins/fzf/fzf.plugin.zsh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'plugins/fzf') diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index b28b97994..27e2d9246 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -24,22 +24,29 @@ fi if [[ -n "${fzf_base}" ]]; then + # 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 + # Setup fzf # --------- - if [[ ! "$PATH" == *$fzf_base/bin* ]]; then + if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then export PATH="$PATH:$fzf_base/bin" fi # Auto-completion # --------------- if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then - [[ $- == *i* ]] && source "$fzf_base/shell/completion.zsh" 2> /dev/null + [[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null fi # Key bindings # ------------ if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then - source "$fzf_base/shell/key-bindings.zsh" + source "${fzf_shell}/key-bindings.zsh" fi else @@ -47,4 +54,4 @@ else "Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc" >&2 fi -unset fzf_base +unset fzf_base fzf_shell dir fzfdirs -- cgit v1.2.3-70-g09d2