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
Install git’s bash completion so that it is loaded on demand #68366
Conversation
Putting the file in $out/share/bash-completion/completions means that it will be loaded on demand by nixpkgs.bash-completion. With the old location, the user would either have to explicitly source the file during bash startup, or set BASH_COMPLETION_COMPAT_DIR before sourcing bash_completion.sh, which will eagerly load everything in that directory.
we have a new way to install these completion files #68329 that you could try here. |
I wanted it to be simple to follow the change (for the reviewer) and to stay with the existing style of the But I can revise the commit if desired. In that case, I would also suggest using |
mkdir -p $out/etc/bash_completion.d | ||
ln -s $out/share/git/contrib/completion/git-completion.bash $out/etc/bash_completion.d/ | ||
ln -s $out/share/git/contrib/completion/git-prompt.sh $out/etc/bash_completion.d/ |
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.
Shouldn't git-prompt.sh also be linked?
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.
The git-prompt.sh
file contains support functions for setting up a custom prompt. It has nothing to do with bash completion (despite its location).
The old bash completion system eagerly loaded all files in etc/bash_completion.d
.
I imagine someone took advantage of this eager loading and installed git-prompt.sh
into etc/bash_completion.d
to have the functions automatically available without requiring the user to manually having to source the file.
With the new location (share/bash_completion/completions
) files are loaded on demand, that is, one would have to type «command»
and press tab, before «command».sh
gets loaded from share/bash_completion/completions
.
Therefore it doesn’t make sense to move git-prompt.sh
to the new location.
It should probably never have been installed in the old location, and with bash completion v1.90 or later, it is not automatically sourced anymore, so if anything should be done, it would probably be to not touch the file at all, but have users source it from share/git/contrib
.
In my case (by default?) |
Try add this to your shell startup (prior to sourcing
|
@sorbits Yes, that works and I thought to use that variable but it was not defined in my environment and that's probably the default state. As There might be some other use cases for that variable I'm not aware of, so I think it would be better to either populate |
You can include the default values like this:
These defaults are from the XDG Base Directory Specification so they will not change in However, I do not think it makes sense to source completions from those locations when you use nixpkgs, only directories controlled by the nix package manager should be referenced by your system to ensure everything is in a known state / reproductible.
I think it would be ideal if it was setup in But lack of default setup just means that we must do it manually in our custom shell startup scripts, not that we should avoid touching the variable. I strongly encourage you to look into this and possibly submit a pull request to change this or at least get a conversation started somewhere where those more knowledgeable about this can weigh in on the pros and cons. If you google for |
Motivation for this change
Putting the bash completion file in
$out/share/bash-completion/completions
means that it will be loaded on demand by bash-completion and is also consistent with most other packages.With the old location, the user would either have to explicitly source the file during bash startup, or set
BASH_COMPLETION_COMPAT_DIR
before sourcingbash_completion.sh
, which will eagerly load everything in that directory.Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)Notify maintainers
cc @peti @the-kenny @wmertens @globin