From b90f76c1411b4a2182f4fd54b5739be5f78410e8 Mon Sep 17 00:00:00 2001 From: Ilya Gorski <52842983+gorsil@users.noreply.github.com> Date: Mon, 15 Jul 2019 00:40:28 +0300 Subject: fzf: Adding support for debian packages --- plugins/fzf/fzf.plugin.zsh | 150 ++++++++++++++++++++++++++++----------------- 1 file changed, 93 insertions(+), 57 deletions(-) (limited to 'plugins/fzf') diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index 27e2d9246..e191bebbd 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -1,57 +1,93 @@ -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" + "/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 [[ -d "${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 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() { + 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 + + local 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 -- cgit v1.2.3-70-g09d2 From 0565251c3bd91994073a265cdb8abb7eac9439e5 Mon Sep 17 00:00:00 2001 From: Ilya Gorski <52842983+gorsil@users.noreply.github.com> Date: Wed, 17 Jul 2019 02:43:00 +0300 Subject: Unset all local functions after running them --- plugins/fzf/fzf.plugin.zsh | 2 ++ 1 file changed, 2 insertions(+) (limited to 'plugins/fzf') diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index e191bebbd..646148297 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -91,3 +91,5 @@ function indicate_error() { # 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 -- cgit v1.2.3-70-g09d2 From f56b678888c0ad4ac71458680d75d88b442cf09b Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Tue, 15 Oct 2019 16:51:51 +0200 Subject: fzf: check for dpkg before checking for fzf in debian Fixes #8253 Co-authored-by: Mariusz B --- plugins/fzf/fzf.plugin.zsh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugins/fzf') diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index 646148297..f701fdf32 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -1,9 +1,9 @@ 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 + # 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}" @@ -58,7 +58,7 @@ function setup_using_base_dir() { function setup_using_debian_package() { - dpkg -s fzf &> /dev/null + (( $+command[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 -- cgit v1.2.3-70-g09d2 From 563c0708ab7100c23aab218a9053a61d81fe1317 Mon Sep 17 00:00:00 2001 From: Jakub Łuczyński Date: Wed, 16 Oct 2019 17:59:06 +0200 Subject: fzf: fix regression (#8269) Typo introduced in f56b678 fixing #8253 --- plugins/fzf/fzf.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/fzf') diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index f701fdf32..fe471a363 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -58,7 +58,7 @@ function setup_using_base_dir() { function setup_using_debian_package() { - (( $+command[dpkg] )) && dpkg -s fzf &> /dev/null + (( $+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 -- cgit v1.2.3-70-g09d2 From 6390afd6de2978ca19920adb4d8958c1ee788f49 Mon Sep 17 00:00:00 2001 From: Meng Bo Date: Thu, 28 Nov 2019 22:41:58 +0800 Subject: fzf: change debian completion file path (#8402) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Newer Debian packages install completions file in /usr/share/doc/fzf/examples/completion.zsh * Default to buster/stretch path if completion file not found See file list in order from older to newer fzf package versions: - https://packages.debian.org/stretch-backports/amd64/fzf/filelist - https://packages.debian.org/buster/amd64/fzf/filelist - https://packages.debian.org/bullseye/amd64/fzf/filelist - https://packages.debian.org/sid/amd64/fzf/filelist Co-authored-by: Marc Cornellà --- plugins/fzf/fzf.plugin.zsh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'plugins/fzf') diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index fe471a363..83626009d 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -67,7 +67,10 @@ function setup_using_debian_package() { # NOTE: There is no need to configure PATH for debian package, all binaries # are installed to /usr/bin by default - local completions="/usr/share/zsh/vendor-completions/_fzf" + # 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 -- cgit v1.2.3-70-g09d2 From 4338a731b77d9f7a73b554667626e35b3fb5f7e3 Mon Sep 17 00:00:00 2001 From: pprugger Date: Thu, 19 Dec 2019 10:50:20 +0100 Subject: fzf: add support for FreeBSD (#8474) --- plugins/fzf/fzf.plugin.zsh | 1 + 1 file changed, 1 insertion(+) (limited to 'plugins/fzf') diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index 83626009d..c8aefd7ab 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -12,6 +12,7 @@ function setup_using_base_dir() { "${HOME}/.fzf" "/usr/local/opt/fzf" "/usr/share/fzf" + "/usr/local/share/examples/fzf" ) for dir in ${fzfdirs}; do if [[ -d "${dir}" ]]; then -- cgit v1.2.3-70-g09d2 From 52f9238b16ddc8a97690b49c8b395e9fe1169b62 Mon Sep 17 00:00:00 2001 From: Roey Darwish Dror Date: Thu, 13 Feb 2020 19:57:52 +0200 Subject: fzf: support for NixOS and Void Linux (#8618) --- plugins/fzf/fzf.plugin.zsh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'plugins/fzf') diff --git a/plugins/fzf/fzf.plugin.zsh b/plugins/fzf/fzf.plugin.zsh index c8aefd7ab..53bdcbc97 100644 --- a/plugins/fzf/fzf.plugin.zsh +++ b/plugins/fzf/fzf.plugin.zsh @@ -10,6 +10,7 @@ function setup_using_base_dir() { 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" @@ -31,8 +32,8 @@ function setup_using_base_dir() { fi if [[ -d "${fzf_base}" ]]; then - # Fix fzf shell directory for Archlinux package - if [[ ! -d "${fzf_base}/shell" ]] && [[ -f /etc/arch-release ]]; 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" -- cgit v1.2.3-70-g09d2