summaryrefslogtreecommitdiff
path: root/plugins/fzf
diff options
context:
space:
mode:
authorMarc Cornellà <marc.cornella@live.com>2020-10-20 23:48:59 +0200
committerGitHub <noreply@github.com>2020-10-20 23:48:59 +0200
commit7d73908223222d3df7f36ed5a362fcfccd770ca5 (patch)
tree3694ab73b1873f1e128b3301467d668fbf0ad07b /plugins/fzf
parentf9f45ca222a0ec6fa867ab3733f15911d1b894e6 (diff)
downloadzsh-7d73908223222d3df7f36ed5a362fcfccd770ca5.tar.gz
zsh-7d73908223222d3df7f36ed5a362fcfccd770ca5.tar.bz2
zsh-7d73908223222d3df7f36ed5a362fcfccd770ca5.zip
fzf: add check for OpenSUSE and OpenBSD packages (#9327)
Diffstat (limited to 'plugins/fzf')
-rw-r--r--plugins/fzf/README.md51
-rw-r--r--plugins/fzf/fzf.plugin.zsh125
2 files changed, 124 insertions, 52 deletions
diff --git a/plugins/fzf/README.md b/plugins/fzf/README.md
index d9617563a..791a3eb6f 100644
--- a/plugins/fzf/README.md
+++ b/plugins/fzf/README.md
@@ -1,33 +1,52 @@
# fzf
-This plugin enables [junegunn's fzf](https://github.com/junegunn/fzf) fuzzy auto-completion and key bindings
+This plugin tries to find [junegunn's fzf](https://github.com/junegunn/fzf) based on where
+it's been installed, and enables its fuzzy auto-completion and key bindings.
To use it, add `fzf` to the plugins array in your zshrc file:
+
```zsh
plugins=(... fzf)
```
## Settings
-Add these before the `plugins=()` line in your zshrc file:
+All these settings should go in your zshrc file, before Oh My Zsh is sourced.
+
+### `FZF_BASE`
+
+Set to fzf installation directory path:
+
+```zsh
+export FZF_BASE=/path/to/fzf/install/dir
+```
+
+### `FZF_DEFAULT_COMMAND`
+
+Set default command to use when input is tty:
```zsh
-# Set fzf installation directory path
-# export FZF_BASE=/path/to/fzf/install/dir
+export FZF_DEFAULT_COMMAND='<your fzf default commmand>'
+```
+
+If not set, the plugin will try to set it to these, in the order in which they're found:
-# Uncomment to set the FZF_DEFAULT_COMMAND
-# export FZF_DEFAULT_COMMAND='<your fzf default commmand>'
+- [`rg`](https://github.com/BurntSushi/ripgrep)
+- [`fd`](https://github.com/sharkdp/fd)
+- [`ag`](https://github.com/ggreer/the_silver_searcher)
-# Uncomment the following line to disable fuzzy completion
-# DISABLE_FZF_AUTO_COMPLETION="true"
+### `DISABLE_FZF_AUTO_COMPLETION`
-# Uncomment the following line to disable key bindings (CTRL-T, CTRL-R, ALT-C)
-# DISABLE_FZF_KEY_BINDINGS="true"
+Set whether to load fzf auto-completion:
+
+```zsh
+DISABLE_FZF_AUTO_COMPLETION="true"
```
-| Setting | Example value | Description |
-|-----------------------------|----------------------------|-------------------------------------------------------------|
-| FZF_BASE | `/path/to/fzf/install/dir` | Set fzf installation directory path (**export**) |
-| FZF_DEFAULT_COMMAND | `fd --type f` | Set default command to use when input is tty (**export**) |
-| DISABLE_FZF_AUTO_COMPLETION | `true` | Set whether to load fzf auto-completion |
-| DISABLE_FZF_KEY_BINDINGS | `true` | Set whether to disable key bindings (CTRL-T, CTRL-R, ALT-C) |
+### `DISABLE_FZF_KEY_BINDINGS`
+
+Set whether to disable key bindings (CTRL-T, CTRL-R, ALT-C):
+
+```zsh
+DISABLE_FZF_KEY_BINDINGS="true"
+```
diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh
index 0b831b7f7..2f48215d5 100644
--- a/plugins/fzf/fzf.plugin.zsh
+++ b/plugins/fzf/fzf.plugin.zsh
@@ -1,9 +1,5 @@
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
+ local fzf_base fzf_shell fzfdirs dir
test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
@@ -31,38 +27,37 @@ function setup_using_base_dir() {
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
+ if [[ ! -d "${fzf_base}" ]]; then
+ return 1
+ fi
- # Setup fzf binary path
- if ! (( ${+commands[fzf]} )) && [[ ! "$PATH" == *$fzf_base/bin* ]]; then
- export PATH="$PATH:$fzf_base/bin"
- fi
+ # 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
- # Auto-completion
- if [[ ! "$DISABLE_FZF_AUTO_COMPLETION" == "true" ]]; then
- [[ $- == *i* ]] && source "${fzf_shell}/completion.zsh" 2> /dev/null
- fi
+ # Setup fzf binary path
+ if (( ! ${+commands[fzf]} )) && [[ "$PATH" != *$fzf_base/bin* ]]; then
+ export PATH="$PATH:$fzf_base/bin"
+ fi
- # Key bindings
- if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
- source "${fzf_shell}/key-bindings.zsh"
- fi
- else
- return 1
+ # Auto-completion
+ if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
+ 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
}
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
+ if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then
+ # Either not a debian based distro, or no fzf installed
return 1
fi
@@ -76,8 +71,8 @@ function setup_using_debian_package() {
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
+ if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
+ source $completions 2> /dev/null
fi
# Key bindings
@@ -88,16 +83,74 @@ function setup_using_debian_package() {
return 0
}
+function setup_using_opensuse_package() {
+ # OpenSUSE installs fzf in /usr/bin/fzf
+ # If the command is not found, the package isn't installed
+ (( $+commands[fzf] )) || return 1
+
+ # The fzf-zsh-completion package installs the auto-completion in
+ local completions="/usr/share/zsh/site-functions/_fzf"
+ # The fzf-zsh-completion package installs the key-bindings file in
+ local key_bindings="/etc/zsh_completion.d/fzf-key-bindings"
+
+ # If these are not found: (1) maybe we're not on OpenSUSE, or
+ # (2) maybe the fzf-zsh-completion package isn't installed.
+ if [[ ! -f "$completions" || ! -f "$key_bindings" ]]; then
+ return 1
+ fi
+
+ # Auto-completion
+ if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
+ source "$completions" 2>/dev/null
+ fi
+
+ # Key bindings
+ if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
+ source "$key_bindings" 2>/dev/null
+ fi
+
+ return 0
+}
+
+function setup_using_openbsd_package() {
+ # openBSD installs fzf in /usr/local/bin/fzf
+ if [[ "$OSTYPE" != openbsd* ]] || (( ! $+commands[fzf] )); then
+ return 1
+ fi
+
+ # The fzf package installs the auto-completion in
+ local completions="/usr/local/share/zsh/site-functions/_fzf_completion"
+ # The fzf package installs the key-bindings file in
+ local key_bindings="/usr/local/share/zsh/site-functions/_fzf_key_bindings"
+
+ # Auto-completion
+ if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
+ source "$completions" 2>/dev/null
+ fi
+
+ # Key bindings
+ if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
+ source "$key_bindings" 2>/dev/null
+ 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
+ cat >&2 <<EOF
+[oh-my-zsh] fzf plugin: Cannot find fzf installation directory.
+Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc
+EOF
}
-# 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
+setup_using_openbsd_package \
+ || setup_using_debian_package \
+ || setup_using_opensuse_package \
+ || setup_using_base_dir \
+ || indicate_error
-unset -f setup_using_debian_package setup_using_base_dir indicate_error
+unset -f setup_using_opensuse_package setup_using_debian_package setup_using_base_dir indicate_error
if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
if (( $+commands[rg] )); then