7d73908223222d3df7f36ed5a362fcfccd770ca5

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

fzf: add check for OpenSUSE and OpenBSD packages (#9327)

Diff

This diff is truncated to protect this page.

  1diff --git a/plugins/fzf/README.md b/plugins/fzf/README.md
  2index d9617563a2c97284a407ca31f0627c144dc88f16..791a3eb6f251ab749d9169d7e55b9e4ee76cc4f3 100644
  3--- a/plugins/fzf/README.md
  4+++ b/plugins/fzf/README.md
  5@@ -1,33 +1,52 @@
  6 # fzf
  7 
  8-This plugin enables [junegunn's fzf](https://github.com/junegunn/fzf) fuzzy auto-completion and key bindings
  9+This plugin tries to find [junegunn's fzf](https://github.com/junegunn/fzf) based on where
 10+it's been installed, and enables its fuzzy auto-completion and key bindings.
 11 
 12 To use it, add `fzf` to the plugins array in your zshrc file:
 13+
 14 ```zsh
 15 plugins=(... fzf)
 16 ```
 17 
 18 ## Settings
 19 
 20-Add these before the `plugins=()` line in your zshrc file:
 21+All these settings should go in your zshrc file, before Oh My Zsh is sourced.
 22+
 23+### `FZF_BASE`
 24+
 25+Set to fzf installation directory path:
 26+
 27+```zsh
 28+export FZF_BASE=/path/to/fzf/install/dir
 29+```
 30+
 31+### `FZF_DEFAULT_COMMAND`
 32+
 33+Set default command to use when input is tty:
 34 
 35 ```zsh
 36-# Set fzf installation directory path
 37-# export FZF_BASE=/path/to/fzf/install/dir
 38+export FZF_DEFAULT_COMMAND='<your fzf default commmand>'
 39+```
 40+
 41+If not set, the plugin will try to set it to these, in the order in which they're found:
 42 
 43-# Uncomment to set the FZF_DEFAULT_COMMAND
 44-# export FZF_DEFAULT_COMMAND='<your fzf default commmand>'
 45+- [`rg`](https://github.com/BurntSushi/ripgrep)
 46+- [`fd`](https://github.com/sharkdp/fd)
 47+- [`ag`](https://github.com/ggreer/the_silver_searcher)
 48 
 49-# Uncomment the following line to disable fuzzy completion
 50-# DISABLE_FZF_AUTO_COMPLETION="true"
 51+### `DISABLE_FZF_AUTO_COMPLETION`
 52 
 53-# Uncomment the following line to disable key bindings (CTRL-T, CTRL-R, ALT-C)
 54-# DISABLE_FZF_KEY_BINDINGS="true"
 55+Set whether to load fzf auto-completion:
 56+
 57+```zsh
 58+DISABLE_FZF_AUTO_COMPLETION="true"
 59 ```
 60 
 61-| Setting                     | Example value              | Description                                                 |
 62-|-----------------------------|----------------------------|-------------------------------------------------------------|
 63-| FZF_BASE                    | `/path/to/fzf/install/dir` | Set fzf installation directory path (**export**)            |
 64-| FZF_DEFAULT_COMMAND         | `fd --type f`              | Set default command to use when input is tty (**export**)   |
 65-| DISABLE_FZF_AUTO_COMPLETION | `true`                     | Set whether to load fzf auto-completion                     |
 66-| DISABLE_FZF_KEY_BINDINGS    | `true`                     | Set whether to disable key bindings (CTRL-T, CTRL-R, ALT-C) |
 67+### `DISABLE_FZF_KEY_BINDINGS`
 68+
 69+Set whether to disable key bindings (CTRL-T, CTRL-R, ALT-C):
 70+
 71+```zsh
 72+DISABLE_FZF_KEY_BINDINGS="true"
 73+```
 74diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh
 75index 0b831b7f7e52099b9283a951c2808deecaed8d79..2f48215d5652a51164d3f15a7fa722a86f620052 100644
 76--- a/plugins/fzf/fzf.plugin.zsh
 77+++ b/plugins/fzf/fzf.plugin.zsh
 78@@ -1,9 +1,5 @@
 79 function setup_using_base_dir() {
 80-    # Declare all variables local not no mess with outside env in any way
 81-    local fzf_base
 82-    local fzf_shell
 83-    local fzfdirs
 84-    local dir
 85+    local fzf_base fzf_shell fzfdirs dir
 86 
 87     test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
 88 
 89@@ -31,38 +27,37 @@ function setup_using_base_dir() {
 90         fi
 91     fi
 92 
 93-    if [[ -d "${fzf_base}" ]]; then
 94-        # Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages
 95-        if [[ ! -d "${fzf_base}/shell" ]]; then
 96-          fzf_shell="${fzf_base}"
 97-        else
 98-          fzf_shell="${fzf_base}/shell"
 99-        fi
100+    if [[ ! -d "${fzf_base}" ]]; then
101+        return 1
102+    fi
103 
104-        # Setup fzf binary path
105-        if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then
106-          export PATH="$PATH:$fzf_base/bin"
107-        fi
108+    # Fix fzf shell directory for Arch Linux, NixOS or Void Linux packages
109+    if [[ ! -d "${fzf_base}/shell" ]]; then
110+        fzf_shell="${fzf_base}"
111+    else
112+        fzf_shell="${fzf_base}/shell"
113+    fi
114 
115-        # Auto-completion
116-        if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
117-          [[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null
118-        fi
119+    # Setup fzf binary path
120+    if (( ! ${+commands[fzf]} )) && [[ "$PATH" != *$fzf_base/bin* ]]; then
121+        export PATH="$PATH:$fzf_base/bin"
122+    fi
123 
124-        # Key bindings
125-        if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
126-          source "${fzf_shell}/key-bindings.zsh"
127-        fi
128-    else
129-        return 1
130+    # Auto-completion
131+    if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
132+        source "${fzf_shell}/completion.zsh" 2> /dev/null
133+    fi
134+
135+    # Key bindings
136+    if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
137+        source "${fzf_shell}/key-bindings.zsh"
138     fi
139 }
140 
141 
142 function setup_using_debian_package() {
143-    (( $+commands[dpkg] )) && dpkg -s fzf &> /dev/null
144-    if (( $? )); then
145-        # Either not a debian based distro, or no fzf installed. In any case skip ahead
146+    if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then
147+        # Either not a debian based distro, or no fzf installed
148         return 1
149     fi
150 
151@@ -76,8 +71,8 @@ function setup_using_debian_package() {
152     local key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
153 
154     # Auto-completion
155-    if [[ $- == *i* ]] && [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
156-         source $completions 2> /dev/null
157+    if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
158+        source $completions 2> /dev/null
159     fi
160 
161     # Key bindings
162@@ -88,16 +83,74 @@ function setup_using_debian_package() {
163     return 0
164 }
165 
166+function setup_using_opensuse_package() {
167+    # OpenSUSE installs fzf in /usr/bin/fzf
168+    # If the command is not found, the package isn't installed
169+    (( $+commands[fzf] )) || return 1
170+
171+    # The fzf-zsh-completion package installs the auto-completion in
172+    local completions="/usr/share/zsh/site-functions/_fzf"
173+    # The fzf-zsh-completion package installs the key-bindings file in
174+    local key_bindings="/etc/zsh_completion.d/fzf-key-bindings"
175+
176+    # If these are not found: (1) maybe we're not on OpenSUSE, or
177+    # (2) maybe the fzf-zsh-completion package isn't installed.