diff options
| author | Marc Cornellà <marc.cornella@live.com> | 2020-02-27 22:55:30 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-27 22:55:30 +0100 | 
| commit | 18ee5dffdc57bb9219ee96b40da006704ac37df1 (patch) | |
| tree | e1fe420cf18fa7a916d5d43c408c6f92ed33b62d /plugins/fzf | |
| parent | d81cd753e0b3a845e8f3549da245dbad102a6e4c (diff) | |
| parent | 368198b7616eb69b396de86d9ec4ff0f35bd72f0 (diff) | |
| download | zsh-18ee5dffdc57bb9219ee96b40da006704ac37df1.tar.gz zsh-18ee5dffdc57bb9219ee96b40da006704ac37df1.tar.bz2 zsh-18ee5dffdc57bb9219ee96b40da006704ac37df1.zip  | |
Merge branch 'master' into clipboard
Diffstat (limited to 'plugins/fzf')
| -rw-r--r-- | plugins/fzf/fzf.plugin.zsh | 157 | 
1 files changed, 100 insertions, 57 deletions
diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index 27e2d9246..53bdcbc97 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -1,57 +1,100 @@ -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 - -  # 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 ! (( ${+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_shell}/completion.zsh" 2> /dev/null -  fi -   -  # Key bindings -  # ------------ -  if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then -    source "${fzf_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 fzf_shell dir fzfdirs +function setup_using_base_dir() { +    # Declare all variables local not no mess with outside env in any way +    local fzf_base +    local fzf_shell +    local fzfdirs +    local dir + +    test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}" + +    if [[ -z "${fzf_base}" ]]; then +        fzfdirs=( +          "${HOME}/.fzf" +          "${HOME}/.nix-profile/share/fzf" +          "/usr/local/opt/fzf" +          "/usr/share/fzf" +          "/usr/local/share/examples/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 [[ -d "${fzf_base}" ]]; then +        # Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages +        if [[ ! -d "${fzf_base}/shell" ]]; then +          fzf_shell="${fzf_base}" +        else +          fzf_shell="${fzf_base}/shell" +        fi + +        # Setup fzf binary path +        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_shell}/completion.zsh" 2> /dev/null +        fi + +        # Key bindings +        if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then +          source "${fzf_shell}/key-bindings.zsh" +        fi +    else +        return 1 +    fi +} + + +function setup_using_debian_package() { +    (( $+commands[dpkg] )) && 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 + +    # Determine completion file path: first bullseye/sid, then buster/stretch +    local completions="/usr/share/doc/fzf/examples/completion.zsh" +    [[ -f "$completions" ]] || 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  | 
