Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ Configuration
This script defines the following global variables. You may override their
default values only after having loaded this script into your ZSH session.

* `ZSH_BASH_COMPLETIONS_FALLBACK_PATH` overrides the default bash completions
path that is set to `/usr/share/bash-completion` by default.

* `ZSH_BASH_COMPLETIONS_FALLBACK_REPLACE_ALL` set (to any value) to allow to
replace all the zsh completions, even if we already have one for the given
command.
Expand Down
28 changes: 14 additions & 14 deletions zsh-bash-completions-fallback.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
[[ -o interactive ]] || return 0

_bash_completions_getter_path=${0:A:h}/bash-completions-getter.sh
_bash_completions_dirs=(
~/.local/share
${(@s/:/)${XDG_DATA_DIRS}} # in NixOS, it contains /run/current-system/sw/share
/data/data/com.termux/files/usr/share # Android Termux
~/.local/state/nix/profile/share # Nix
/home/linuxbrew/.linuxbrew/share # Homebrew for Linux
/opt/share # Homebrew for arm macOS
/usr/local/share # Homebrew for x86 macOS
/${MINGW_ARCH:-mingw64}/share # Windows Msys2
/usr/share
)

function _bash_completions_fallback_completer {
emulate -L zsh
Expand Down Expand Up @@ -63,17 +74,12 @@ function _bash_completions_fetch_supported_commands {
setopt extended_glob typeset_silent no_short_loops
unsetopt nomatch

local bash_completions=${ZSH_BASH_COMPLETIONS_FALLBACK_PATH:-${${(@s/:/)${XDG_DATA_DIRS:-/usr/share}}[1]}/bash-completion}
local -a dirs=(
${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions
)

for dir in ${(@s/:/)${XDG_DATA_DIRS:-/usr/local/share:/usr/share}}; do
local dir dirs=($BASH_COMPLETION_USER_DIR)
for dir in "${_bash_completions_dirs[@]}"; do
dirs+=("$dir/bash-completion/completions")
done

dirs+=("$bash_completions/completions")

local c
for dir in "${dirs[@]}"; do
for c in "$dir"/*; do
[ ! -f "$c" ] && continue
Expand All @@ -91,7 +97,6 @@ function _bash_completions_fetch_supported_commands {
}

function _bash_completions_load {
local bash_completions=${ZSH_BASH_COMPLETIONS_FALLBACK_PATH:-${${(@s/:/)${XDG_DATA_DIRS:-/usr/share}}[1]}/bash-completion}
local reserved_words=(
"do"
"done"
Expand Down Expand Up @@ -122,11 +127,6 @@ function _bash_completions_load {
"typeset"
)

if ! [ -f /etc/bash_completion ] &&
! [ -f "$bash_completions/bash_completion" ]; then
return 1;
fi

local -a -U _bash_completions_commands=()
_bash_completions_fetch_supported_commands

Expand Down