1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-12-18 18:31:59 +00:00

refactor(fzf): adopt code style and simplify function naming (#10514)

This commit is contained in:
Logan Linn 2021-12-17 04:18:28 -08:00 committed by GitHub
parent 41c15a2159
commit 010c36d4ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
function setup_using_base_dir() { function fzf_setup_using_base_dir() {
local fzf_base fzf_shell fzfdirs dir local fzf_base fzf_shell fzfdirs dir
test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}" test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
@ -58,7 +58,7 @@ function setup_using_base_dir() {
} }
function setup_using_debian_package() { function fzf_setup_using_debian() {
if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then
# Either not a debian based distro, or no fzf installed # Either not a debian based distro, or no fzf installed
return 1 return 1
@ -96,7 +96,7 @@ function setup_using_debian_package() {
return 0 return 0
} }
function setup_using_opensuse_package() { function fzf_setup_using_opensuse() {
# OpenSUSE installs fzf in /usr/bin/fzf # OpenSUSE installs fzf in /usr/bin/fzf
# If the command is not found, the package isn't installed # If the command is not found, the package isn't installed
(( $+commands[fzf] )) || return 1 (( $+commands[fzf] )) || return 1
@ -125,7 +125,7 @@ function setup_using_opensuse_package() {
return 0 return 0
} }
function setup_using_openbsd_package() { function fzf_setup_using_openbsd() {
# openBSD installs fzf in /usr/local/bin/fzf # openBSD installs fzf in /usr/local/bin/fzf
if [[ "$OSTYPE" != openbsd* ]] || (( ! $+commands[fzf] )); then if [[ "$OSTYPE" != openbsd* ]] || (( ! $+commands[fzf] )); then
return 1 return 1
@ -149,21 +149,21 @@ function setup_using_openbsd_package() {
return 0 return 0
} }
function indicate_error() { # Indicate to user that fzf installation not found if nothing worked
cat >&2 <<EOF function fzf_setup_error() {
cat >&2 <<'EOF'
[oh-my-zsh] fzf plugin: Cannot find fzf installation directory. [oh-my-zsh] fzf plugin: Cannot find fzf installation directory.
Please add \`export FZF_BASE=/path/to/fzf/install/dir\` to your .zshrc Please add `export FZF_BASE=/path/to/fzf/install/dir` to your .zshrc
EOF EOF
} }
# Indicate to user that fzf installation not found if nothing worked fzf_setup_using_openbsd \
setup_using_openbsd_package \ || fzf_setup_using_debian \
|| setup_using_debian_package \ || fzf_setup_using_opensuse \
|| setup_using_opensuse_package \ || fzf_setup_using_base_dir \
|| setup_using_base_dir \ || fzf_setup_error
|| indicate_error
unset -f setup_using_opensuse_package setup_using_debian_package setup_using_base_dir indicate_error unset -f -m 'fzf_setup_*'
if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
if (( $+commands[rg] )); then if (( $+commands[rg] )); then