Skip to content

Conversation

gaelicWizard
Copy link
Contributor

@gaelicWizard gaelicWizard commented Jul 28, 2021

Description

Uses the $BASH_COMPLETION variable to locate the script if defined, falling back to the existing waterfall. For the final case (Homebrew), use $OSTYPE instead of running an external command, and then import the script itself rather than the wrapper in the profile.d folder.

Motivation and Context

The bash-completion script itself allows for $BASH_COMPLETION, $BASH_COMPLETION_COMPAT_DIR, and $BASH_COMPLETION_DIR to be set prior to invocation and in fact at least $BASH_COMPLETION_COMPAT_DIR needs to be in order to be useful. This can allow for different versions to be used when, for example, Bash is v4+ or not.

However, the wrapper script in .../etc/profile.d/bash_completion.sh on many distributions actually short-circuits if $BASH_COMPLETION is defined. When the profile.d wrapper is used while $BASH_COMPLETION is already defined, bash-completion is simply never once loaded as the wrapper and the actual script disagree about this variable.

How Has This Been Tested?

This is live on my branch on my computer currently.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • If my change requires a change to the documentation, I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • If I have added a new file, I also added it to clean_files.txt and formatted it using lint_clean_files.sh.
  • I have added tests to cover my changes, and all the new and existing tests pass.

Copy link
Member

@NoahGorny NoahGorny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another nice idea- I will let @davidpfarrell take a look as well and merge if he also approves 😄

@gaelicWizard
Copy link
Contributor Author

Anything else needed for this PR? 😃

Instead of using the profile.d version, just invoke the script. The profile.d script preemptively short-circuits if it thinks that bash-completions has already been loaded, which it does by using the $BASH_COMPLETION variable, which is expressly supported by upstream to specify the location of the script...so it will entirely be never loaded if this is set.
Bash-completion supports pre-defining $BASH_COMPLETION as the path to the main script, so use that if it's defined.

Alsö, don't load homebrew's completion if we've successfully loaded one already.
@NoahGorny
Copy link
Member

nope- well done!

@NoahGorny NoahGorny merged commit 0fb9d0c into Bash-it:master Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants