Skip to content

Autocomplete after the eol command - #216

Merged
hugovk merged 7 commits into
hugovk:mainfrom
romainx:feat-125
Oct 15, 2025
Merged

Autocomplete after the eol command#216
hugovk merged 7 commits into
hugovk:mainfrom
romainx:feat-125

Conversation

@romainx

@romainx romainx commented Jul 26, 2024

Copy link
Copy Markdown
Contributor

Hello,

This is a draft to resolve #125.
As the project is using argparse, I thought it was a good idea to use argcomplete.
This implementation is very simple but it seems to do the trick.

# register eol with the shell's completion framework by running register-python-argcomplete:
eval "$(register-python-argcomplete eol)"
# use it
eol ne
nextcloud  nextjs  netbsd  nexus  neo4j  neos  --    

Cheers 🍰

@hugovk hugovk added the changelog: Added For new features label Jul 26, 2024
@romainx
romainx marked this pull request as ready for review July 26, 2024 07:42
@hugovk

hugovk commented Jul 26, 2024

Copy link
Copy Markdown
Owner

Thanks for this!

# register eol with the shell's completion framework by running register-python-argcomplete:
eval "$(register-python-argcomplete my-python-app)"
# use it
eol ne
nextcloud  nextjs  netbsd  nexus  neo4j  neos  --    

Is my-python-app correct here?

@romainx

romainx commented Jul 26, 2024

Copy link
Copy Markdown
Contributor Author

Hello

Is my-python-app correct here?

Sorry no 😓 , it should be replaced by eol. Fixed in the PR description.

@hugovk

hugovk commented Jul 26, 2024

Copy link
Copy Markdown
Owner

Thanks, so does the eval need to be run just once, or once per new shell or something?

@romainx

romainx commented Jul 26, 2024

Copy link
Copy Markdown
Contributor Author

@hugovk the use of eval is for one time activation (for the current shell), there are several options that are nicely described in the pytest documentation for bash completion.
I pushed a commit to support global completion.

@hugovk

hugovk commented Jul 26, 2024

Copy link
Copy Markdown
Owner

The eval works for me, but I've run activate-global-python-argcomplete (on macOS with iterm2):

activate-global-python-argcomplete
Defaulting to system-wide installation.
Installing /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/argcomplete/bash_completion.d/_python-argcomplete to /opt/homebrew/share/zsh/site-functions/_python-argcomplete...
Installed.
Installing /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/argcomplete/bash_completion.d/_python-argcomplete to /opt/homebrew/etc/bash_completion.d/python-argcomplete...
Installed.
Please restart your shell or source the installed file to activate it.

And opened a new shell, but it's not completing:

eol ne

Do you know why?

@romainx

romainx commented Jul 26, 2024

Copy link
Copy Markdown
Contributor Author

Works on my side on new shell but only after I added the flag # PYTHON_ARGCOMPLETE_OK in the code (cli.py). Have you pulled this commit to perform your test?

Instead, the shell will look for the string PYTHON_ARGCOMPLETE_OK in the first 1024 bytes of any executable that it's running completion for, and if it's found, follow the rest of the argcomplete protocol as described above.
--source

@hugovk

hugovk commented Jul 27, 2024

Copy link
Copy Markdown
Owner

Yes:

head --lines 2 src/norwegianblue/cli.py
#!/usr/bin/env python3
# PYTHON_ARGCOMPLETE_OKpip install -e . --quieteol ne<tab>

New terminal tab:

eol ne<tab>

@romainx

romainx commented Jul 27, 2024

Copy link
Copy Markdown
Contributor Author

Sorry for that. The script python-argcomplete is located on my side at:

  • /usr/local/share/zsh/site-functions/_python-argcomplete for zsh
  • /usr/local/etc/bash_completion.d/python-argcomplete for bash

Seems that on your side it's installed at the following locations:

  • /opt/homebrew/share/zsh/site-functions/_python-argcomplete for zsh
  • /opt/homebrew/etc/bash_completion.d/python-argcomplete for bash

Could you please try to source the one corresponding to your shell to check if it exists and if it solves the problem?

source /opt/homebrew/share/zsh/site-functions/_python-argcomplete

@hugovk

hugovk commented Jul 27, 2024

Copy link
Copy Markdown
Owner

Sorry for that. The script python-argcomplete is located on my side at:

  • /usr/local/share/zsh/site-functions/_python-argcomplete for zsh
  • /usr/local/etc/bash_completion.d/python-argcomplete for bash

Seems that on your side it's installed at the following locations:

  • /opt/homebrew/share/zsh/site-functions/_python-argcomplete for zsh
  • /opt/homebrew/etc/bash_completion.d/python-argcomplete for bash

That's right.

Could you please try to source the one corresponding to your shell to check if it exists and if it solves the problem?

source /opt/homebrew/share/zsh/site-functions/_python-argcomplete

Yes, that works.

@romainx

romainx commented Jul 27, 2024

Copy link
Copy Markdown
Contributor Author

I don't know why it is not sourced automatically by your shell 🤔?

@hugovk

hugovk commented Jul 28, 2024

Copy link
Copy Markdown
Owner

I've no idea...

python3.13 is the default interpreter on this machine, I also have:

locate _python-argcomplete
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/argcomplete/bash_completion.d/_python-argcomplete
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/argcomplete/bash_completion.d/_python-argcomplete
/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/argcomplete/bash_completion.d/_python-argcomplete
/opt/homebrew/Cellar/pipx/1.6.0/libexec/lib/python3.12/site-packages/argcomplete/bash_completion.d/_python-argcomplete
/opt/homebrew/share/zsh/site-functions/_python-argcomplete

activate-global-python-argcomplete on my path is for 3.13:

which activate-global-python-argcomplete
/Library/Frameworks/Python.framework/Versions/3.13/bin/activate-global-python-argcomplete

But when I run it, it installs from 3.13 to a Homebrew path:

activate-global-python-argcomplete
Defaulting to system-wide installation.
Installing /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/argcomplete/bash_completion.d/_python-argcomplete to /opt/homebrew/share/zsh/site-functions/_python-argcomplete...
Installed.
Installing /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/argcomplete/bash_completion.d/_python-argcomplete to /opt/homebrew/etc/bash_completion.d/python-argcomplete...
Installed.
Please restart your shell or source the installed file to activate it.

I don't use Homebrew Python for anything other than letting Homebrew manage it for its own use, so it feels like a bug that the 3.13 activate-global-python-argcomplete installs completion for another interpreter, let alone the Homebrew one.

Anyway, it also works if I source that 3.13 one in a new tab. What do you suggest? Should I add manual sourcing of that to my ~/.zshrc or something?

@romainx

romainx commented Jul 29, 2024

Copy link
Copy Markdown
Contributor Author

zsh

From this helper.

Completion functions for commands are stored in files with names beginning with an underscore _, and these files should be placed in a directory listed in the $fpath variable. You can add a directory to $fpath by adding a line like this to your ~/.zshrc file:

So you can check if your fpath variable contains the location of the autocomplete script installation.

echo $fpath | grep /opt/homebrew/share/zsh/site-functions  

If it's not the case you could add a line in your ~/.zshrc file.

fpath=(/opt/homebrew/share/zsh/site-functions $fpath)

bash

Based on my understanding of this answer.
A .bash_completion script should perform this kind of source.

for bcfile in ~/.bash_completion.d/* ; do
  [ -f "$bcfile" ] && . $bcfile
done

@hugovk

hugovk commented Aug 5, 2024

Copy link
Copy Markdown
Owner

So you can check if your fpath variable contains the location of the autocomplete script installation.

echo $fpath | grep /opt/homebrew/share/zsh/site-functions  

Yes, it's the first (and second) entry in my $fpath.

@ozskywalker

Copy link
Copy Markdown

Could we get this merged in? would be super helpful for speeding things up in the CLI.

@codecov

codecov Bot commented Oct 13, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.61%. Comparing base (7baf0e3) to head (964197d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #216   +/-   ##
=======================================
  Coverage   98.61%   98.61%           
=======================================
  Files           7        7           
  Lines         432      433    +1     
=======================================
+ Hits          426      427    +1     
  Misses          6        6           
Flag Coverage Δ
macos-latest 98.61% <100.00%> (+<0.01%) ⬆️
ubuntu-latest 98.61% <100.00%> (+<0.01%) ⬆️
windows-latest ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hugovk

hugovk commented Oct 13, 2025

Copy link
Copy Markdown
Owner

I've resolved the conflict, and tested again, it now works for me! 🎉

eval "$(register-python-argcomplete eol)"eol p<tab>
pci-dss            panos       pangp
phoenix-framework  photon      perl
phpmyadmin         phpbb       php
pixel-watch        pigeonhole  pixel
plone              plesk       pnpm
postfix            pop-os      podman
postmarketos       powershell  postgresql
prometheus         privatebin  proftpd
proxmox-ve         protractor  puppet
python                                     --

I'll get this merged and released soon, hopefully this week.

Would someone like to suggest some text to stick in the README about this?

Comment thread src/norwegianblue/cli.py Outdated
Comment thread src/norwegianblue/cli.py Outdated
@hugovk
hugovk merged commit 0f4afdd into hugovk:main Oct 15, 2025
48 checks passed
@romainx
romainx deleted the feat-125 branch November 1, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: Added For new features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Autocomplete after the eol command

3 participants