zsh-workers
 help / color / mirror / code / Atom feed
* autocompletion's odd behaviour with packages installed through pip
@ 2024-08-21 19:45 Silejonu
  2024-08-22  3:16 ` Jun T
  0 siblings, 1 reply; 2+ messages in thread
From: Silejonu @ 2024-08-21 19:45 UTC (permalink / raw)
  To: Zsh Workers

[-- Attachment #1: Type: text/plain, Size: 649 bytes --]

Autocompletion does not work for packages installed through pip until a) the user logs out and logs back in , or b) the user deactivates the current Python venv and reactivates it. Note that, for comparison, Bash is not affected by this issue.

Steps to reproduce:
`python -m venv /tmp/test`
`source /tmp/test/bin/activate`
`pip install ansible`
Type `ans` and hit tab to autocomplete
Nothing happens (though syntax highlighting recognizes than `ansible` is a valid command)
`deactivate`
`source /tmp/test/bin/activate`
Type `ans` and hit tab to autocomplete
This now works correctly

Tested on Zsh 5.8 (CentOS Stream 9, RHEL 9) & 5.9 (Arch Linux).

[-- Attachment #2: Type: text/html, Size: 1126 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: autocompletion's odd behaviour with packages installed through pip
  2024-08-21 19:45 autocompletion's odd behaviour with packages installed through pip Silejonu
@ 2024-08-22  3:16 ` Jun T
  0 siblings, 0 replies; 2+ messages in thread
From: Jun T @ 2024-08-22  3:16 UTC (permalink / raw)
  To: zsh-workers; +Cc: Silejonu


> 2024/08/22 4:45, Silejonu <silejonu@tuta.com> wrote:
> 
> Steps to reproduce:
>     • `python -m venv /tmp/test`
>     • `source /tmp/test/bin/activate`
>     • `pip install ansible`
>     • Type `ans` and hit tab to autocomplete
>     • Nothing happens (though syntax highlighting recognizes than `ansible` is a valid command)

This is not specific to pip.
zsh keeps an internal hash for all the commands in the PATH,
and this hash is not automatically updated when a new command
is added to your PATH.

A simple workaround is to manually run the rehash (or 'hash -r')
builtin to update the hash ('source activate' also does this):

% pip install ansible
% rehash
% ansi<TAB>

If you feel typing 'rehash' is tedious, then you can put

zstyle ':completion:*:commands' rehash on

into your .zshrc. Then 'rehash' is run every time you complete
a command name. If you don't notice any slowdown then this may be
the easiest solution.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-22  3:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-21 19:45 autocompletion's odd behaviour with packages installed through pip Silejonu
2024-08-22  3:16 ` Jun T

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).