Compare commits

...

3 Commits

Author SHA1 Message Date
smac89
b7fb0a55c0
fix(heroku): fix XDG cache directory name and code style (#10436) 2021-12-17 13:45:06 +01:00
Sean Flanigan
52a46ec362
feat(fzf): support fzf in Cygwin (#9463)
Closes #9463
2021-12-17 13:22:58 +01:00
Logan Linn
010c36d4ab
refactor(fzf): adopt code style and simplify function naming (#10514) 2021-12-17 13:18:28 +01:00
2 changed files with 168 additions and 143 deletions

View File

@ -1,176 +1,201 @@
function setup_using_base_dir() {
local fzf_base fzf_shell fzfdirs dir
function fzf_setup_using_base_dir() {
local fzf_base fzf_shell fzfdirs dir
test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
test -d "${FZF_BASE}" && fzf_base="${FZF_BASE}"
if [[ -z "${fzf_base}" ]]; then
fzfdirs=(
"${HOME}/.fzf"
"${HOME}/.nix-profile/share/fzf"
"${XDG_DATA_HOME:-$HOME/.local/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
fzfdirs=(
"${HOME}/.fzf"
"${HOME}/.nix-profile/share/fzf"
"${XDG_DATA_HOME:-$HOME/.local/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[fzf-share]} )) && dir="$(fzf-share)" && [[ -d "${dir}" ]]; then
fzf_base="${dir}"
elif (( ${+commands[brew]} )) && dir="$(brew --prefix fzf 2>/dev/null)"; then
if [[ -d "${dir}" ]]; then
fzf_base="${dir}"
fi
fi
if (( ${+commands[fzf-share]} )) && dir="$(fzf-share)" && [[ -d "${dir}" ]]; then
fzf_base="${dir}"
elif (( ${+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
return 1
fi
if [[ ! -d "${fzf_base}" ]]; then
return 1
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
# 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
# Setup fzf binary path
if (( ! ${+commands[fzf]} )) && [[ "$PATH" != *$fzf_base/bin* ]]; then
export PATH="$PATH:$fzf_base/bin"
fi
# Auto-completion
if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
source "${fzf_shell}/completion.zsh" 2> /dev/null
fi
# 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
# Key bindings
if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
source "${fzf_shell}/key-bindings.zsh"
fi
}
function setup_using_debian_package() {
if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then
# Either not a debian based distro, or no fzf installed
return 1
fi
function fzf_setup_using_debian() {
if (( ! $+commands[dpkg] )) || ! dpkg -s fzf &>/dev/null; then
# Either not a debian based distro, or no fzf installed
return 1
fi
# NOTE: There is no need to configure PATH for debian package, all binaries
# are installed to /usr/bin by default
# NOTE: There is no need to configure PATH for debian package, all binaries
# are installed to /usr/bin by default
local completions key_bindings
local completions key_bindings
case $PREFIX in
*com.termux*)
# Support Termux package
completions="${PREFIX}/share/fzf/completion.zsh"
key_bindings="${PREFIX}/share/fzf/key-bindings.zsh"
;;
*)
# Determine completion file path: first bullseye/sid, then buster/stretch
completions="/usr/share/doc/fzf/examples/completion.zsh"
[[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf"
key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
;;
esac
case $PREFIX in
*com.termux*)
# Support Termux package
completions="${PREFIX}/share/fzf/completion.zsh"
key_bindings="${PREFIX}/share/fzf/key-bindings.zsh"
;;
*)
# Determine completion file path: first bullseye/sid, then buster/stretch
completions="/usr/share/doc/fzf/examples/completion.zsh"
[[ -f "$completions" ]] || completions="/usr/share/zsh/vendor-completions/_fzf"
key_bindings="/usr/share/doc/fzf/examples/key-bindings.zsh"
;;
esac
# Auto-completion
if [[ -o interactive && "$DISABLE_FZF_AUTO_COMPLETION" != "true" ]]; then
source $completions 2> /dev/null
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
fi
# Key bindings
if [[ ! "$DISABLE_FZF_KEY_BINDINGS" == "true" ]]; then
source $key_bindings
fi
return 0
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
function fzf_setup_using_opensuse() {
# 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"
# 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
# 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
# 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
# Key bindings
if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
source "$key_bindings" 2>/dev/null
fi
return 0
return 0
}
function setup_using_openbsd_package() {
# openBSD installs fzf in /usr/local/bin/fzf
if [[ "$OSTYPE" != openbsd* ]] || (( ! $+commands[fzf] )); then
return 1
fi
function fzf_setup_using_openbsd() {
# 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"
# 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
# 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
# Key bindings
if [[ "$DISABLE_FZF_KEY_BINDINGS" != "true" ]]; then
source "$key_bindings" 2>/dev/null
fi
return 0
return 0
}
function indicate_error() {
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
function fzf_setup_using_cygwin() {
# Cygwin installs fzf in /usr/local/bin/fzf
if [[ "$OSTYPE" != cygwin* ]] || (( ! $+commands[fzf] )); then
return 1
fi
# The fzf-zsh-completion package installs the auto-completion in
local completions="/etc/profile.d/fzf-completion.zsh"
# The fzf-zsh package installs the key-bindings file in
local key_bindings="/etc/profile.d/fzf.zsh"
# 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
}
# Indicate to user that fzf installation not found if nothing worked
setup_using_openbsd_package \
|| setup_using_debian_package \
|| setup_using_opensuse_package \
|| setup_using_base_dir \
|| indicate_error
function fzf_setup_error() {
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
}
unset -f setup_using_opensuse_package setup_using_debian_package setup_using_base_dir indicate_error
fzf_setup_using_openbsd \
|| fzf_setup_using_debian \
|| fzf_setup_using_opensuse \
|| fzf_setup_using_cygwin \
|| fzf_setup_using_base_dir \
|| fzf_setup_error
unset -f -m 'fzf_setup_*'
if [[ -z "$FZF_DEFAULT_COMMAND" ]]; then
if (( $+commands[rg] )); then
export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git/*"'
elif (( $+commands[fd] )); then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
elif (( $+commands[ag] )); then
export FZF_DEFAULT_COMMAND='ag -l --hidden -g "" --ignore .git'
fi
if (( $+commands[rg] )); then
export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git/*"'
elif (( $+commands[fd] )); then
export FZF_DEFAULT_COMMAND='fd --type f --hidden --exclude .git'
elif (( $+commands[ag] )); then
export FZF_DEFAULT_COMMAND='ag -l --hidden -g "" --ignore .git'
fi
fi

View File

@ -1,9 +1,9 @@
HEROKU_AC_CACHE_DIR="$HOME/.cache"
if [ "$(uname -s)" = "Darwin" ]; then
HEROKU_AC_CACHE_DIR="$HOME/Library/Caches"
if [[ "$OSTYPE" = darwin* ]]; then
cache_dir="${HOME}/Library/Caches"
else
cache_dir="${XDG_CACHE_HOME:-"${HOME}/.cache"}"
fi
if [ ! -z "$XDG_CACHE_HOME" ]; then
HEROKU_AC_CACHE_DIR="$XDG_CACHE_DIR"
fi
HEROKU_AC_ZSH_SETUP_PATH=$HEROKU_AC_CACHE_DIR/heroku/autocomplete/zsh_setup
[ -f $HEROKU_AC_ZSH_SETUP_PATH ] && source $HEROKU_AC_ZSH_SETUP_PATH
setup_path="${cache_dir}/heroku/autocomplete/zsh_setup"
[[ -f "$setup_path" ]] && source $setup_path
unset cache_dir setup_path