completions/git: Refactor using brace expansions, etc.

- Use brace expansions to generate prefixed paths
- Check if the completion file is non-empty
- Specify explicit exit value to "return" for trap handlers
- Clean up the initialization function after initialization
This commit is contained in:
Koichi Murase 2022-02-05 13:22:59 +09:00
parent a8971e3c7d
commit c6fb27acb9

View File

@ -14,12 +14,10 @@ _omb_completion_git_initialize() {
# contain prefix or suffix for architectures and versions.
path="${path%/*}"
local prefix="${path%/bin}" file
for file in share/bash-completion/completions/git share/git-core/contrib/completion/git-completion.bash;
do
local _file="$prefix/$file"
if [[ -f $_file && -r $_file ]]; then
source "$_file"
return
for file in "$prefix"/share/{bash-completion/completions/git,git-core/contrib/completion/git-completion.bash}; do
if [[ -f $file && -r $file && -s $file ]]; then
source "$file"
return $?
fi
done
done
@ -27,3 +25,4 @@ _omb_completion_git_initialize() {
fi
}
_omb_completion_git_initialize
unset -f _omb_completion_git_initialize