Skip to content

Commit be010c8

Browse files
committed
feat: Iterate directories to search bash-completion
1 parent 41ef0b9 commit be010c8

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

zsh-bash-completions-fallback.plugin.zsh

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
[[ -o interactive ]] || return 0
22

33
_bash_completions_getter_path=${0:A:h}/bash-completions-getter.sh
4+
_bash_completions_dirs=(
5+
${(@s/:/)${XDG_DATA_DIRS}}
6+
~/.local/share
7+
/data/data/com.termux/files/usr/share # Android Termux
8+
~/.local/state/nix/profile/share # Nix without NixOS
9+
/run/current-system/sw/share # NixOS
10+
/home/linuxbrew/.linuxbrew/share # Homebrew for Linux
11+
/opt/share # Homebrew for arm macOS
12+
/usr/local/share # Homebrew for x86 macOS
13+
/${MINGW_ARCH:-mingw64}/share # Windows Msys2
14+
/usr/share
15+
)
416

517
function _bash_completions_fallback_completer {
618
emulate -L zsh
@@ -63,17 +75,12 @@ function _bash_completions_fetch_supported_commands {
6375
setopt extended_glob typeset_silent no_short_loops
6476
unsetopt nomatch
6577

66-
local bash_completions=${ZSH_BASH_COMPLETIONS_FALLBACK_PATH:-${${(@s/:/)${XDG_DATA_DIRS:-/usr/share}}[1]}/bash-completion}
67-
local -a dirs=(
68-
${BASH_COMPLETION_USER_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion}/completions
69-
)
70-
71-
for dir in ${(@s/:/)${XDG_DATA_DIRS:-/usr/local/share:/usr/share}}; do
78+
local dir dirs=($BASH_COMPLETION_USER_DIR)
79+
for dir in "${_bash_completions_dirs[@]}"; do
7280
dirs+=("$dir/bash-completion/completions")
7381
done
7482

75-
dirs+=("$bash_completions/completions")
76-
83+
local c
7784
for dir in "${dirs[@]}"; do
7885
for c in "$dir"/*; do
7986
[ ! -f "$c" ] && continue
@@ -91,7 +98,17 @@ function _bash_completions_fetch_supported_commands {
9198
}
9299

93100
function _bash_completions_load {
94-
local bash_completions=${ZSH_BASH_COMPLETIONS_FALLBACK_PATH:-${${(@s/:/)${XDG_DATA_DIRS:-/usr/share}}[1]}/bash-completion}
101+
local dir bash_completions
102+
if [ -d "$ZSH_BASH_COMPLETIONS_FALLBACK_PATH" ]; then
103+
bash_completions=$ZSH_BASH_COMPLETIONS_FALLBACK_PATH
104+
else
105+
for dir in "${_bash_completions_dirs[@]}"; do
106+
if [ -d $dir/bash-completion ]; then
107+
bash_completions=$dir/bash-completion
108+
break
109+
fi
110+
done
111+
fi
95112
local reserved_words=(
96113
"do"
97114
"done"

0 commit comments

Comments
 (0)