tartansandal / conda-bash-completion

Bash completion support for conda
GNU General Public License v3.0
148 stars 7 forks source link

How to debug why it is not working on MacOS? #22

Closed cipri-tom closed 5 months ago

cipri-tom commented 6 months ago

Hi there,

I have conda, mamba and completion for both installed in the base environment, on MacOS, but with bash ! At the same time, I have bash-completion2 installed with homebrew.

For some reason, conda doesn't complete. However, mamba completes, but only once, with repoquery. Second <tab> in mamba <tab>repoquery<tab> gives an error: -bash: _comp_conda: command not found .

So it seems that the installation did not work. How can I debug this ?

In my .bashrc, I have this: [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

And in my .bash_profile the block that conda initialization puts, but nothing about completion.

Maybe I need to put the conda file somewhere, instead of direct installation ? But I'm not sure where. Any pointers?

Thank you very much for the package, and for the maintainance !

tartansandal commented 6 months ago

Hi @cipri-tom. :wave:

First question: which installation method did you use?

Second question: do you have your base environment active by default?

My first guess is that you have the mamba completion script installed and active, but not the conda one.

cipri-tom commented 6 months ago

Hi @tartansandal !

I used method 1: mamba install mamba-bash-completion, which installs 3 packages: bash-completion, conda-bash-completion, and mamba-bash-completion.

(base) $ conda list | grep compl
bash-completion           2.11                 h694c41f_1    conda-forge
conda-bash-completion     1.7                  h694c41f_1    conda-forge
mamba-bash-completion     1.0                  h694c41f_1    conda-forge

Yes, the base is active by default.

I suspect the completion is installed in a folder that bash doesn't look into. I don't know which one, nor how to tell the completion part to look there (I suppose it's not source )

Thank you for your help in this !

tartansandal commented 6 months ago

Apologies for the late reply -- I've been sick with COVID and complications for the passed 4 weeks.

Since you already had bash_completion2 installed via homebrew, using the (manual) method2 should work. And to keep things clean do mamba remove mamba-bash-completion. I'm not sure what will happen if both methods are used at the same time.

Note, manual installation method2 puts the files under ~/.local/share/... whereas the automatic installation method puts the files under your conda/mamba base environment and used special tweaks to the included bash_completion library to get them to be called.

cipri-tom commented 5 months ago

Hey, no worries ! Thank you for taking effort through the sickness to look at this ! Hope you recover well and fully !!

Great, I've installed manually. I've put the conda from this repo, and mamba from the mamba completion into /usr/local/Cellar/bash-completion@2/2.13.0/share/bash-completion/completions because I wasn't sure if ~/.local/share/... would be taken into account.

And yes, conda works now.

mamba completes, but with weird stuff:

$ mamba ac<tab>
aclocal       aclocal-1.10  aclocal-1.11  aclocal-1.12  aclocal-1.13  aclocal-1.14  aclocal-1.15  aclocal-1.16  acpi

Ah, it's because I was in the completions directory, so it was completing with names from there. If I move to home folder, mamba doesn't suggest any completions. Should I open an issue in mamba completion repo ?

Here's the trace from set -x, if it helps:

Logs of mamba completion ``` $ set -x $ mamba in+ local cur prev words cword comp_args + _comp_initialize -- mamba in mamba + local exclude= opt_split= outx= errx= inx= + local flag OPTIND=1 OPTARG= OPTERR=0 + getopts n:e:o:i:s flag -- mamba in mamba + shift 1 + (( 3 )) + comp_args=("$@") + COMPREPLY=() + local 'redir=@(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|&])|<?(>))' + _comp_get_words -n '<>&' cur prev words cword + local exclude= flag i OPTIND=1 + words=() + local cur cword words + upargs=() + upvars=() + local upargs upvars vcur= vcword= vprev= vwords= + getopts c:i:n:p:w: flag -n '<>&' cur prev words cword + case $flag in + exclude='<>&' + getopts c:i:n:p:w: flag -n '<>&' cur prev words cword + [[ 6 -ge 3 ]] + case ${!OPTIND} in + vcur=cur + (( OPTIND += 1 )) + [[ 6 -ge 4 ]] + case ${!OPTIND} in + vprev=prev + (( OPTIND += 1 )) + [[ 6 -ge 5 ]] + case ${!OPTIND} in + vwords=words + (( OPTIND += 1 )) + [[ 6 -ge 6 ]] + case ${!OPTIND} in + vcword=cword + (( OPTIND += 1 )) + [[ 6 -ge 7 ]] + _comp__get_cword_at_cursor '<>&' words cword cur + words=() + local cword words + _comp__reassemble_words '<>&' words cword + local exclude= i j line ref + [[ -n <>& ]] + exclude='[<>&]' + printf -v cword %s 1 + [[ -n [<>&] ]] + line='mamba in' + (( i = 0, j = 0 )) + (( i < 2 )) + [[ 0 -gt 0 ]] + ref='words[0]' + printf -v 'words[0]' %s mamba + line=' in' + (( i == COMP_CWORD )) + (( i++, j++ )) + (( i < 2 )) + [[ 1 -gt 0 ]] + [[ in == +([<>&]) ]] + ref='words[1]' + printf -v 'words[1]' %s in + line= + (( i == COMP_CWORD )) + printf -v cword %s 1 + (( i++, j++ )) + (( i < 2 )) + (( i == COMP_CWORD )) + local i cur= index=8 'lead=mamba in' + [[ 8 -gt 0 ]] + [[ -n mamba in ]] + [[ -n mambain ]] + cur='mamba in' + (( i = 0 )) + (( i <= cword )) + [[ 8 -ge 5 ]] + [[ mamba != \m\a\m\b\a ]] + (( i < cword )) + local old_size=8 + cur=' in' + local new_size=3 + (( index -= old_size - new_size )) + (( ++i )) + (( i <= cword )) + [[ 3 -ge 2 ]] + [[ i != \i\n ]] + cur=in + (( index > 0 )) + (( index-- )) + [[ 2 -ge 2 ]] + [[ in != \i\n ]] + (( i < cword )) + (( ++i )) + (( i <= cword )) + [[ -n in ]] + [[ ! -n in ]] + (( index < 0 )) + local 'IFS= ' + local words cword cur + _comp_upvars -a2 words mamba in -v cword 1 -v cur in + (( 10 )) + (( 10 )) + case $1 in + [[ -n 2 ]] + printf %d 2 + [[ -n words ]] + unset -v words + eval 'words=("${@:3:2}")' ++ words=("${@:3:2}") + shift 4 + (( 6 )) + case $1 in + [[ -n cword ]] + unset -v cword + eval 'cword="$3"' ++ cword=1 + shift 3 + (( 3 )) + case $1 in + [[ -n cur ]] + unset -v cur + eval 'cur="$3"' ++ cur=in + shift 3 + (( 0 )) + [[ -n cur ]] + upvars+=("$vcur") + upargs+=(-v "$vcur" "$cur") + [[ -n cword ]] + upvars+=("$vcword") + upargs+=(-v "$vcword" "$cword") + [[ -n prev ]] + local value= + (( cword >= 1 )) + value=mamba + upvars+=("$vprev") + upargs+=(-v "$vprev" "$value") + [[ -n words ]] + local 'IFS= ' + upvars+=("$vwords") + upargs+=(-a"${#words[@]}" "$vwords" ${words+"${words[@]}"}) + (( 4 )) + local cur cword prev words + _comp_upvars -v cur in -v cword 1 -v prev mamba -a2 words mamba in + (( 13 )) + (( 13 )) + case $1 in + [[ -n cur ]] + unset -v cur + eval 'cur="$3"' ++ cur=in + shift 3 + (( 10 )) + case $1 in + [[ -n cword ]] + unset -v cword + eval 'cword="$3"' ++ cword=1 + shift 3 + (( 7 )) + case $1 in + [[ -n prev ]] + unset -v prev + eval 'prev="$3"' ++ prev=mamba + shift 3 + (( 4 )) + case $1 in + [[ -n 2 ]] + printf %d 2 + [[ -n words ]] + unset -v words + eval 'words=("${@:3:2}")' ++ words=("${@:3:2}") + shift 4 + (( 0 )) + _comp_compgen_variables + [[ in =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]] + [[ in =~ ^(\$\{[#!]?)([A-Za-z0-9_]*)\[([^]]*)$ ]] + [[ in =~ ^\$\{[#!]?[A-Za-z0-9_]*\[.*]$ ]] + return 1 + [[ in == @(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|&])|<?(>))* ]] + [[ mamba == @(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|&])|<?(>)) ]] + local i skip + (( i = 1 )) + (( i < 2 )) + [[ in == @(?(+([0-9])|{[a-zA-Z_]*([a-zA-Z_0-9])})@(>?([>|&])|&])|<?(>))* ]] + (( i++ )) + (( 1 )) + (( i < 2 )) + (( cword <= 0 )) + prev=mamba + [[ -n '' ]] + return 0 + compopt -o bashdefault -o default ```
tartansandal commented 5 months ago

The last line of the logs:

  • compopt -o bashdefault -o default

indicates that it is falling back to default completion. Maybe you need to restart your terminal to get a fresh shell after moving the files around? :thinking: Note: the lasy-loading of the completion scripts may have become confused.

cipri-tom commented 5 months ago

🤦 that was it, indeed ! Sorry I made you read through all that for such a simple fix .

Thanks immensely for your help !

Wishing you great health !