Closed Nxt3 closed 5 years ago
.bash_profile is loaded before .bashrc so depending on where you have the completions being loaded, your call to complete
Is likely happening before the completions are sourced.
I'm doing something similar with git: complete -o default -o nospace -F _git g
and that works fine. It's only the yarn one.
The completions are being loaded in .bash_profile
as well.
So _git
is working differently since git-completion
has nothing to do with bash-completion@2
.
I'm thinking it's not possible to access the functions defined in your autocompletion globally. 🤔
Yes it is.
Here's an example from my dotfiles....
Can I ask what that's doing (like, step-by-step)? I've never seen something in bash like that.
# IF the yarn command exists in the PATH
command -v yarn \
# AND a completion was able to be sourced for yarn
&& __load_completion yarn \
# AND after sourcing the yarn completions, there exists a function available named _yarn
&& command -v _yarn \
# THEN complete my alias for yarn "y" with the yarn completions
&& complete -F _yarn y
Awesome. This helped me achieve what I was looking for. Thank you so much!
I've created a function in my
.bash_profile
that I want to include autocompletions from yarn for.This is what I'm trying:
complete -o default -o nospace -F _yarn yarnupgrade
but I get the following error:
bash: completion: function '_yarn' not found
Ideally I'd like to only autocomplete the choices output from
yarn upgrade
.Otherwise, yarn completion works great!