-
Notifications
You must be signed in to change notification settings - Fork 404
fix: load from more new style completion dirs #1569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3478,15 +3478,15 @@ _comp_load() | |
| if [[ ${BASH_COMPLETION_USER_DIR-} ]]; then | ||
| _comp_split -F : dirs "$BASH_COMPLETION_USER_DIR" | ||
| else | ||
| dirs=("${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion") | ||
| dirs=("${XDG_DATA_HOME:-$HOME/.local/share}/bash-completion/completions") | ||
| fi | ||
|
|
||
| # 2) From the location of bash_completion: Completions relative to the main | ||
| # script. This is primarily for run-in-place-from-git-clone setups, where | ||
| # we want to prefer in-tree completions over ones possibly coming with a | ||
| # system installed bash-completion. (Due to usual install layouts, this | ||
| # often hits the correct completions in system installations, too.) | ||
| dirs+=("$_comp__base_directory") | ||
| dirs+=("$_comp__base_directory"/completions{,-core,-fallback}) | ||
|
|
||
| # 3) From bin directories extracted from the specified path to the command, | ||
| # the real path to the command, and $PATH | ||
|
|
@@ -3496,28 +3496,24 @@ _comp_load() | |
| _comp_split -aF : paths "$PATH" | ||
| for dir in "${paths[@]%/}"; do | ||
| [[ $dir == ?*/@(bin|sbin) ]] && | ||
| dirs+=("${dir%/*}/share/bash-completion") | ||
| dirs+=("${dir%/*}/share/bash-completion"/completions{,-core,-fallback}) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the same reason, I think we don't want to load Also, as I mentioned above, I would like to suggest exchanging the ordering of |
||
| done | ||
|
|
||
| # 4) From XDG_DATA_DIRS or system dirs (e.g. /usr/share, /usr/local/share): | ||
| # Completions in the system data dirs. | ||
| _comp_split -F : paths "${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" && | ||
| dirs+=("${paths[@]/%//bash-completion}") | ||
| dirs+=("${paths[@]/%//bash-completion}"/completions{,-core,-fallback}) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we search the system I also think loading external In short, I think the completions in
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, agreed. |
||
|
|
||
| # Look up and source | ||
| shift | ||
| local -a source_args=("$@") | ||
|
|
||
| local i | ||
| for i in "${!dirs[@]}"; do | ||
| dir=${dirs[i]}/completions | ||
| for dir in "${dirs[@]}"; do | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result of this is that we end up loading completions without the .bash suffix from more dirs we did before this change. We may want to tighten that up some. Could check if the dir ends with -core or -fallback and load only .bash for them. That isn't 100% correct in the case if someone has for whatever reason configured their BASH_COMPLETION_USER_DIR to have one of those suffixes (we'd want to load both with and without .bash from there for backwards compatibility).
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree to check the suffix |
||
| [[ -d $dir ]] || continue | ||
| for compfile in "$cmdname.bash" "$cmdname"; do | ||
| _comp_load__visit_file "$dir/$compfile" && return 0 | ||
| done | ||
| done | ||
| _comp_load__visit_file "$_comp__base_directory/completions-core/$cmdname.bash" && return 0 | ||
| _comp_load__visit_file "$_comp__base_directory/completions-fallback/$cmdname.bash" && return 0 | ||
|
|
||
| # Look up simple "xspec" completions | ||
| [[ -v _comp_xspecs[$cmdname] || -v _xspecs[$cmdname] ]] && | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BASH_COMPLETION_USER_DIRis supposed to contain a path like~/.local/share/bash-completion, so we need to suffix/completionto them too. I think we can use_comp_compgen. For example, something like this:_comp_compgen -Rv dirs -F : -- -W '$BASH_COMPLETION_USER_DIR' -S /completions, though I haven't tested this carefully.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't thought of this too deeply, but I think we do not need to do that. This dir is a single directory to load completions from, solely under the user's control, I don't think we need to add any more structure or segments to it. Adding would also be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm README.md seems to disagree with me, I misremembered.
$BASH_COMPLETION_USER_DIRis by the way not documented in doc/configuration.md, only its$XDG_CONFIG_HOME/bash_completionfallback is. We should fix that.