tartansandal / conda-bash-completion

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

Not working on Ubuntu 20.04 #9

Closed josiahcoad closed 3 years ago

josiahcoad commented 3 years ago

Hi, I have the following config: Ubuntu 20.04 conda-bash-completion 1.5 conda 4.9.2

echo $BASH_VERSION -> 5.0.17(1)-release echo $SHELL -> /bin/bash

I ran >>conda install -c conda-forge conda-bash-completion from the base environment.

It is not working. (i.e. I tried conda in[TAB] and nothing happens.) Any suggestions? Thanks

tartansandal commented 3 years ago

Hi @josiahcoad. A couple of quick questions:

josiahcoad commented 3 years ago

hi @tartansandal thanks for the quick reply. Yes to both of those! I even rebooted my computer!

tartansandal commented 3 years ago

No probs. :smile: Some more questions:

josiahcoad commented 3 years ago
tartansandal commented 3 years ago

OK. So with miniconda, some people prefer to disable the automatic activation of their base environment by setting auto_activate_base: false in their ~/.condarc file. Have you done this?

josiahcoad commented 3 years ago

I haven't. In fact, I don't have a ~/.condarc file.

tartansandal commented 3 years ago

Damn. That's all the easy solutions out of the way. As a simple sanity check (while I spin up a docker container with the new Ubuntu) could you run:

> CONDA_ROOT=~/anaconda3   # <- set to your Anaconda/Miniconda installation directory
> source $CONDA_ROOT/etc/profile.d/bash_completion.sh 

And see if that triggers conda completion in the same shell.

josiahcoad commented 3 years ago

Actually, it doesn't!

tartansandal commented 3 years ago

Hmm interesting.

I've just spun up a fresh ubuntu:focal container, installed the latest miniconda, installed conda-bash-completion and its dependencies into the base environment, started a fresh shell and completion works. So I think we can rule out the new Ubuntu as an issue :smile:.

The above sanity check failing is probably the key: Could you run:

> bash -vx  $CONDA_ROOT/etc/profile.d/bash_completion.sh 

and post the output as a code block (inside triple backticks)?

Cheers!

josiahcoad commented 3 years ago

Well, thanks for checking! I wonder if something is overriding the tab functionality??

> bash -vx  $CONDA_ROOT/etc/profile.d/bash_completion.sh 
# shellcheck shell=sh disable=SC1091,SC2039,SC2166
# Check for interactive bash and that we haven't already been sourced.
if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${CONDA_BASH_COMPLETION_LOADED-}" = x ]; then

    # Check for recent enough version of bash.
    if [ "${BASH_VERSINFO[0]}" -gt 4 ] || \
       [ "${BASH_VERSINFO[0]}" -eq 4 -a "${BASH_VERSINFO[1]}" -ge 1 ]; then
        [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
            . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
        if shopt -q progcomp && [ -r /home/josiahcoad/miniconda3/share/bash-completion/bash_completion ]; then
            # Source completion code.
            . /home/josiahcoad/miniconda3/share/bash-completion/bash_completion
        fi
    fi

fi
+ '[' 'x5.0.17(1)-release' '!=' x -a x '!=' x -a x = x ']'
tartansandal commented 3 years ago

Bingo! :partying_face:

Your interactive prompt PS1is not defined for some reason, so we skip loading completion functions since they won't be used.

Maybe something in your set up is undefining PS1? Perhaps some fancy prompt code? Some custom tweaks in your .bashrc or .bash_profile?

tartansandal commented 3 years ago

Actually, ignore my previous comment. I'm an idiot :crying_cat_face:.

Try running:

> bash -vxi  $CONDA_ROOT/etc/profile.d/bash_completion.sh 

and post the output as a code block. (I forgot to add the interactive -i to the bash command)

tartansandal commented 3 years ago

It occurs that this will be a lot of output. Just post the lines after <<< conda initialize <<< :smile:

josiahcoad commented 3 years ago

Oh haha np. I was pretty confused.

mmm are you sure? It's hundreds of lines of code...

josiahcoad commented 3 years ago

Got it.

export LD_LIBRARY_PATH=:/home/josiahcoad/miniconda3/envs/tf1-nv/lib/
+ export LD_LIBRARY_PATH=:/home/josiahcoad/miniconda3/envs/tf1-nv/lib/
+ LD_LIBRARY_PATH=:/home/josiahcoad/miniconda3/envs/tf1-nv/lib/

alias cdac='conda deactivate'
+ alias 'cdac=conda deactivate'
alias cact='conda activate'
+ alias 'cact=conda activate'
alias ccre='conda create -n'
+ alias 'ccre=conda create -n'
alias crem='conda env remove -n'
+ alias 'crem=conda env remove -n'
#source /etc/profile.d/bash_completion.sh

bind '"\e[A": history-search-backward'
+ bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
+ bind '"\e[B": history-search-forward'

alias editb='nano ~/.bashrc && source ~/.bashrc'
+ alias 'editb=nano ~/.bashrc && source ~/.bashrc'
alias pw="cat ~/txt/passwords.txt | grep -i "
+ alias 'pw=cat ~/txt/passwords.txt | grep -i '
# shellcheck shell=sh disable=SC1091,SC2039,SC2166
# Check for interactive bash and that we haven't already been sourced.
if [ "x${BASH_VERSION-}" != x -a "x${PS1-}" != x -a "x${CONDA_BASH_COMPLETION_LOADED-}" = x ]; then

    # Check for recent enough version of bash.
    if [ "${BASH_VERSINFO[0]}" -gt 4 ] || \
       [ "${BASH_VERSINFO[0]}" -eq 4 -a "${BASH_VERSINFO[1]}" -ge 1 ]; then
        [ -r "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ] && \
            . "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
        if shopt -q progcomp && [ -r /home/josiahcoad/miniconda3/share/bash-completion/bash_completion ]; then
            # Source completion code.
            . /home/josiahcoad/miniconda3/share/bash-completion/bash_completion
        fi
    fi

fi
+ '[' 'x5.0.17(1)-release' '!=' x -a 'x(base) \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' '!=' x -a xY = x ']'
tartansandal commented 3 years ago

Excellent! So the conda bash completion code is being loaded, but it's just not doing anything. Lets check the conda environment variables. Could you run:

> env | grep CONDA

and post the output in a code block?

josiahcoad commented 3 years ago

Thanks again for helping!!!

CONDA_EXE=/home/josiahcoad/miniconda3/bin/conda
CONDA_PREFIX=/home/josiahcoad/miniconda3
CONDA_PROMPT_MODIFIER=(base) 
_CE_CONDA=
CONDA_SHLVL=1
CONDA_PYTHON_EXE=/home/josiahcoad/miniconda3/bin/python
CONDA_DEFAULT_ENV=base
tartansandal commented 3 years ago

Not a problems :wink:

That env looks good. Now for some local variables:

> __comp_conda_ensure_root
> echo $CONDA_SOURCE
josiahcoad commented 3 years ago

/home/josiahcoad/miniconda3/lib/python3.8/site-packages/conda

tartansandal commented 3 years ago

Thanks for sticking with this. There are a lot of edge cases and variations in bash setups, so it's great to get detailed insight into end user environments and experiences. Also good to squash bugs. :smile:

That CONDA_SOURCE looks good.

Hmm one thing I've noticed with bash_completion in my Ubuntu container is that some times I have to hit <TAB> twice to trigger the completion. This happens with completing options for other commands than conda. I'm clutching at straws now, but could you try

> conda in<tab><tab>
josiahcoad commented 3 years ago

It works! I swear I smashed the tab a million times before lol so idk what changed.

tartansandal commented 3 years ago

He he. We still may have a problem, since we are in the 'sanity check' environment. Try a fresh shell or terminal before we start celebrating :smile:

josiahcoad commented 3 years ago

haha did this actually just to make sure. It seems like it is working!

tartansandal commented 3 years ago

That's great! Hope you enjoy the new completions. Back to watching the cricket :smile:

josiahcoad commented 3 years ago

Hahaha thanks so much. you really went above&beyond in support!