This peaked my interest, as my nvm completion works out of the gate for me with a new login shell.
If you take a look at the nvm completion file, the first evaluated statement reads:
if ! command -v nvm &> /dev/null; then
This is checking if
nvm can be invoked, and if it can’t it bails. This explains why you have to manually source it, as it isn’t invokable until later in your profile’s evaluation. Which was strange, until I tried a
which nvm that yielded nothing, and then a
type nvm, which spit out a huge function definition. Eureka, nvm is just a bash function. So if you move the source command displayed via
brew info nvm above your sourcing of
bash_completion, you’ll be in business. In general it’s advisable to activate bash-completion at the end of your profile, after paths are set, spells are cast, etc (especially if you have legacy completions that get eager loaded, which is how homebrew installs formula provided ones for compatibility).
# Example .bash_profile statement ordering.
# Make sure these statements execute before sourcing bash completion.
if [[ -f /usr/local/opt/nvm/nvm.sh ]]; then
# Then you can bring in completions.
if [[ -f /usr/local/share/bash-completion/bash_completion ]]; then