conda-incubator / conda-zsh-completion Goto Github PK
View Code? Open in Web Editor NEWzsh completion for conda
License: Do What The F*ck You Want To Public License
zsh completion for conda
License: Do What The F*ck You Want To Public License
I went through all the steps and when I try to do autocompletion, all I get are 3 dots and nothing else. A quick error does flash and disappear, but it says that there was a parse error on line 417 of _conda. Of course this may change with updates, so here is what that offending line is on my side:
FWIW:
Line 30 in 382d840
It may be my thick skull, but I found this bit confusing. For clarity, if you are using oh-my-zsh
then your implementation (assuming your oh-my-zsh
is blank slate) should look like this:
# ~/.zshrc
# Add the plug in next to git.
plugins=(git conda-zsh-completion)
# Don't change this line.
source $ZSH/oh-my-zsh.sh
# Auto load after sourcing oh-my-zsh.sh.
autoload -U compinit && compinit
see https://github.com/conda/conda/blob/master/CHANGELOG.md#new-features
completion for the command names (even without the environment names) would be nice.
I've successfully and happily made the completions work on an Ubuntu 18.04 box by following the installation instructions, however on my laptop the procedure does not work. I'm using Ubuntu 16.04, conda 4.6.14, zsh 5.1.1 and the latest oh-my-zsh (078f64dcf9c56f45d1d5e9e49dd5709baedc1386)
I've installed miniconda on my Mac with Sonoma 14.4.1.
I'm running zsh v5.9, having oh-my-zsh installed.
Unfortunately, conda-zsh-completetion doesn't find my conda environments for completion, it just always inserts base
.
Is there any way I can debug this further?
I noticed that my envs are stored under ~/anaconda3/envs
- is there some way to specify it too?
I know you declare the license in the _conda
source, but how about adding a LICENSE file to make it easier for users to find, and so GitHub can automatically detect it and label your repo as so licensed?
I am using oh-my-zsh in a Mac. For me, the way I found to make the plugin work was doing the following in the .zshrc
file:
git clone https://github.com/esc/conda-zsh-completion ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/conda-zsh-completion
plugins=(git conda-zsh-completion) # this was, by default, plugins=(git)
source $ZSH/oh-my-zsh.sh
:autoload -U compinit && compinit
This was slightly different than (what I understood) the instructions said.
The difference is that I purposely put the step 3 line after the sourcing of oh-my-zsh.sh
.
If I put step 3 line just below step 2 line it does not work (possibly the command gets overwriten in oh-my-zsh.sh
...).
I wonder why this happened in my machine and if my case is the rule or the exception.
In case it happens to at least some people, do you think it is worth adapting the readme to specifying the step 3 should be after source $ZSH/oh-my-zsh.sh
?
thanks
conda aa<TAB>
should return an error since no subcommand started with aa
, but it comes a weird error and ruins the $PROMT
.
$ conda aa<TAB>
$ conda aa_main_complete:202: permission denied:
_main_complete:202: permission denied:
conda conda aa
No matches for: `conda commands'
Tried following instructions but its not working for me
I tried this in my zshrc and also in a current session:
# cloned repo
fpath+=/path/to/where/you/installed/conda-zsh-completion
compinit
# also tried compinit conda
When I try tab completion it doesnt work. I also see no errors or anything so not sure how to debug this
Great zsh completion when using zsh & conda.
Just a little problem: when i tried to complete 'conda activate', it will always show all my environment variables before my conda env list. Something like:
My system is CentOS 7.9.2009, and I use oh-my-zsh. I have done following steps to install:
git clone https://github.com/esc/conda-zsh-completion ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/conda-zsh-completion
(add to .zshrc)
plugins=(… conda-zsh-completion)
autoload -U compinit && compinit
I am not super familiar with shell, which is why a documentation / step by step howto or examples for different use cases, would be really appreciated
I often have conda environments in local directories like .venv
, .venv-broken
, .venv-3.12
. Unfortunately conda activate <TAB>
does not complete to them.
Please add installation instruction
I read _conda
file but don't understand!
conda activate
does not complete existing named envs other then base
.
(base) > $ # Pressing `tab` after `conda activate` with _no_ prefix yields --
(base) > $ conda activate base base base base base base base base base # etc.
(base) > $ # Pressing `tab` after `conda activate` with _something_ prefix yields --
(base) > $ conda activate something_main_complete:202: permission denied:
_main_complete:202: permission denied:
_main_complete:202: permission denied:
(base) > $ conda env list # other envs exist
# conda environments:
#
ishow-oxip /homes/harelw/.conda/envs/ishow-oxip
py3.7-mx-build /homes/harelw/.conda/envs/py3.7-mx-build
py3.7-opencv /homes/harelw/.conda/envs/py3.7-opencv
py3.7-oxip-mx-test /homes/harelw/.conda/envs/py3.7-oxip-mx-test
py3.7-oxucicd-mx-dev /homes/harelw/.conda/envs/py3.7-oxucicd-mx-dev
base * /usr/local/conda
(base) > $ cat ~/.conda/environments.txt # also here, for completeness
/homes/harelw/.conda/envs/py3.7-oxip-mx-test
/homes/harelw/.conda/envs/ishow-oxip
/homes/harelw/.conda/envs/py3.7-mx-build
/homes/harelw/.conda/envs/py3.7-oxucicd-mx-dev
/homes/harelw/.conda/envs/py3.7-opencv
(base) > $ # other compeltions work
(base) > $ conda env # pressed tab
create -- Create an environment based on an environment file
export -- Export a given environment
list -- List the Conda environments
remove -- Remove an environment
update -- Update the current environment based on environment file
oh-my-zsh
,_conda
:
git clone https://github.com/esc/conda-zsh-completion ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/conda-zsh-completion
~/.zshrc
autoload
after / before source $ZSH/oh-my-zsh.sh
4.8.2
miniconda
installationubuntu 18.04
Many thanks,
Harel
This works really well, thanks! Maybe it could be useful to have it in the zsh-completions project?
When type conda -
and press tab
, my terminal shows these:
$ conda -
--help
--version
-h
-V
-- show this help message and exit
-- show programs version number and exit
--help
--version
-h
-V
-- show this help message and exit
-- show programs version number and exit
--help
--version
-h
-V
-- show this help message and exit
-- show programs version number and exit
I uses oh-my-zsh
to manage this plugin.
When trying to complete a command in conda create ...
, the whole completion crashes with __conda_package_available:5: command not found: python
.
Then, zsh doesn't respond anymore. When using a KeyboardInterrupt, this error is shown:
--- Logging error ---
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/core/subdir_data.py", line 165, in query_all
result = tuple(
^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/concurrent/futures/_base.py", line 619, in result_iterator
yield _result_or_cancel(fs.pop())
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/concurrent/futures/_base.py", line 317, in _result_or_cancel
return fut.result(timeout)
^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/concurrent/futures/_base.py", line 451, in result
self._condition.wait(timeout)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/threading.py", line 327, in wait
waiter.acquire()
KeyboardInterruptDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/exception_handler.py", line 17, in call
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/cli/main.py", line 83, in main_subshell
exit_code = do_call(args, parser)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/cli/conda_argparse.py", line 164, in do_call
result = getattr(module, func_name)(args, parser)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/cli/main_search.py", line 92, in execute
SubdirData.query_all(spec, channel_urls, subdirs),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/core/subdir_data.py", line 164, in query_all
with Executor() as executor:
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/concurrent/futures/_base.py", line 647, in exit
self.shutdown(wait=True)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/concurrent/futures/thread.py", line 235, in shutdown
t.join()
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/threading.py", line 1119, in join
self._wait_for_tstate_lock()
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/threading.py", line 1139, in _wait_for_tstate_lock
if lock.acquire(block, timeout):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterruptDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/gateways/logging.py", line 127, in emit
self.flush()
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/logging/init.py", line 1094, in flush
self.stream.flush()
BrokenPipeError: [Errno 32] Broken pipe
Call stack:
File "/opt/homebrew/Caskroom/miniconda/base/bin/conda", line 13, in
sys.exit(main())
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/cli/main.py", line 128, in main
return conda_exception_handler(main, *args, **kwargs)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/exception_handler.py", line 388, in conda_exception_handler
return_value = exception_handler(func, *args, **kwargs)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/exception_handler.py", line 20, in call
return self.handle_exception(exc_val, exc_tb)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/exception_handler.py", line 71, in handle_exception
self._print_conda_exception(CondaError("KeyboardInterrupt"), _format_exc())
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/exception_handler.py", line 84, in _print_conda_exception
print_conda_exception(exc_val, exc_tb)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/exceptions.py", line 1256, in print_conda_exception
logger.info("%s\n" % exc_json)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/logging/init.py", line 1489, in info
self._log(INFO, msg, args, **kwargs)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/logging/init.py", line 1634, in _log
self.handle(record)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/logging/init.py", line 1644, in handle
self.callHandlers(record)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/logging/init.py", line 1706, in callHandlers
hdlr.handle(record)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/logging/init.py", line 978, in handle
self.emit(record)
File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.11/site-packages/conda/gateways/logging.py", line 132, in emit
self.handleError(record)
Message: '{\n "caused_by": "None",\n "error": "CondaError: KeyboardInterrupt",\n "exception_name": "CondaError",\n "exception_type": "<class 'conda.CondaError'>",\n "message": "KeyboardInterrupt"\n}\n'
Arguments: ()
Exception ignored in: <_io.TextIOWrapper name='' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
When waiting for something to happen, after some minutes it starts printing lots of text, which look like a json formatted list of packages including all metadata but I'm not sure what it is.
as title
I am seeing bad alignment in my conda completions when using menu selection. I really have no idea how this works though, so I'm not sure if this is the completion's fault or zsh.
I am using zsh v5.3.1 on macOS 10.13 beta:
% zsh --version
zsh 5.3.1 (x86_64-apple-darwin17.0.0)
The relevant section of my zshrc:
# Completion
#--------------------
autoload -Uz compinit && compinit -u
zstyle ':completion:*' use-cache true # Cache completion to `${ZDOTDIR}/.zcompcache`
zstyle ':completion:*' squeeze-slashes true # Strip slashes from directories
zstyle ':completion:*' menu select # Make the menu interactive with arrow keys
bindkey '^I' menu-expand-or-complete
bindkey '^[[Z' reverse-menu-complete
The results I am seeing:
% conda build
build -- tool for building conda packages
bundle -- Create or extract a "bundle package" (EXPERIMENTAL)
clean -- Remove unused packages and caches.
config -- Modify configuration values in .condarc.
create -- Create a new conda environment from a list of specified packages.
env -- Manage environments.
help -- Displays a list of available conda commands and their help strings.
info -- Display information about current conda install.
init -- Initialize conda into a regular environment. (DEPRECATED)
install -- Install a list of packages into a specified conda environment.
list -- List linked packages in a conda environment.
package -- Low-level conda package utility. (EXPERIMENTAL)
remove -- Remove a list of packages from a specified conda environment.
run -- Launches an application installed with Conda.
search -- Search for packages and display their information.
uninstall -- Alias for conda remove
update -- Update conda packages.
The current implementation is a bit slow, if you look at it from the perspective of navigating in terminal:
https://github.com/esc/conda-zsh-completion/blob/4121e838c83fb84461b2c1332929ab34a26fbf62/_conda#L131
My benchmark (for 10 runs):
➜ bash -c "time for i in {1..10}; do conda info -e | sed '1,2d' | cut -f1 -d' ' >> /dev/null; done"
real 0m3.070s
user 0m2.467s
sys 0m0.594s
My proposed change:
echo base && ls -1 ${${CONDA_EXE}%bin/conda}/envs && echo
(echo at the end is not required but I wanted both implementations to create exactly the same output)
and benchmark (for 10 runs):
➜ bash -c "time for i in {1..10}; do (echo base && ls -1 ${${CONDA_EXE}%bin/conda}/envs && echo) >> /dev/null; done"
real 0m0.039s
user 0m0.013s
sys 0m0.021s
I've been using this replacement for over a year now for conda activate
and I didn't have any issues.
I can create a PR if you think this change is reasonable.`
I tried installing the completion via antibody, which loads the plugin into $fpath
fine. However, it does not work in my dotfiles due my placement of autoload -U compinit; compinit
. For all of my other completion settings (including https://github.com/zsh-users/zsh-completions/), compinit
must be run before they are sourced. By contrast, conda-zsh-completion requires that compinit
be run after it is sourced. So my .zshrc ends up looking like:
autoload -U compinit; compinit
source /path/to/completion_settings.zsh # includes the zstyle commands for conda-zsh-completion
source /antibody/plugin/source.zsh # includes conda-zsh-completion in $fpath
compinit # only required for conda-zsh-completion
Two primary questions:
I'm not familiar enough with zsh completions to figure out the answers to either of these unfortunately.
Hi,
Thanks for creating this.
Could you please create a tag for the latest version (which I believe includes _mamba
- 8 months ago)?
That would allow package managers to create a new version including the latest changes.
Thanks!
How can I get this plugin working with micromamba with antigen / oh-my-zsh in addition to conda / miniconda (conda works great!)? I see micromamba referenced here: https://github.com/conda-incubator/conda-zsh-completion/blob/2cc833a65037399bffaa149780beb2dd5376859e/_conda#L1C2-L1C32
Removing conda-zsh-completion from .zshrc solves the problem.
~
base ❯ conda env create -n xxx python=3.8
SpecNotFound: Invalid name, try the format: user/package
user@host$ conda env list
# conda environments:
#
test_conda /home/public/user/.conda/envs/test_conda
base * /home/public/conda/anaconda3
py36-torch1.4 /home/public/conda/envs/py36-torch1.4
user@host$ pwd
/home/public/user
user@host$ conda activate
base test_conda
user@host$ conda activate py
I cannot completion other environment, except the environment created by myself.
Hi, I'm trying to use this plugin with Prezto but it's not turning on automatically.
All my other Prezto config files are default. Here's the relevant part in my zshrc
:
# env suggetions for conda
fpath+=/home/minhduc0711/conda-zsh-completion
# zsh configuration framework
if [[ -s "${ZDOTDIR:-$HOME}/.zprezto/init.zsh" ]]; then
source "${ZDOTDIR:-$HOME}/.zprezto/init.zsh"
fi
However if I run compinit
after starting a new shell then it works again. Any ideas on how to fix this? Thank you.
what about fish?
I installed _conda into $fpath and it mostly works as expected.
But: Completion goes into endless loop when completing conda info -
. Interrupt by pressing ^C two times gives:
File "<string>", line 3, in <module>
File "/Users/mb/miniconda3/lib/python3.12/json/__init__.py", line 293, in load
return loads(fp.read(),
^^^^^^^^^
KeyboardInterrupt
<<< schnipp, der vollständige traceback ist in der angehängten Datei >>>
% zsh --version (conda)myzsh
zsh --version
zsh 5.9 (x86_64-apple-darwin22.0)
% conda -V (conda)myzsh
conda 24.5.0
% conda info -e (conda)myzsh
# conda environments:
#
base * /Users/mb/miniconda3
graphviz /Users/mb/miniconda3/envs/graphviz
objc /Users/mb/miniconda3/envs/objc
pan /Users/mb/miniconda3/envs/pan
py3c /Users/mb/miniconda3/envs/py3c
I was wondering how hard it would be extend this to support auto-completion for source activate
(which would list the available conda environements).?
There is some discussion about it in conda/conda#2595 and conda/conda#822 suggesting that it might be more simply achievable with zsh than bash...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.