zsh-autocomplete icon indicating copy to clipboard operation
zsh-autocomplete copied to clipboard

Recent dir completion gets in the way of file completion

Open CharlesARoy opened this issue 2 years ago • 8 comments

This might be a bug, but for some autocompletions, the suggestions are a little off. One solution might be to add the ability to set the suggestion category priorities unilaterally or even, which categories are prioritized by program. For example:

If I'm in a directory with the following files and I type vim ar

anaconda3/
bin/
lib/
man/
share/
share.txt
tools/
zsh/

All that gets suggested is a recent directory (in which one of the subdirectories starts with "ar"): image

Ideally, zsh-autocomplete would know that vim is a text editor and prioritize the file containing "ar" in the current directory. However, even without knowing that, it should at least show matches in the current directory so that I can tab through them and select what I want.

Similarly, if I type cd ar, all that gets suggested is the recent directory, without the "share" directory showing up: image

To deal with this, it might be useful to offer a setting where you could do one of the following:

  • Unilaterally decide which suggestion categories are shown and how they are sorted (e.g., maybe I never want to see "recent directories" and I always want "files" to be suggested first, followed by "directories", etc).
  • Decide which suggestion categories to show and how they are sorted by program. (e.g., for vim, I only ever want to see suggestions that are "files", and for cd, I might want to always see "directories" followed by "recent directories", etc).

Another observation (which might be a bug) is that when I type cd ol, rather than suggesting the directory "tools", which actually has "ol" in it, it suggests "lib", which doesn't. Not sure why that happens. image

Let me know if you need any specific information about my setup. Thanks for the help!

CharlesARoy avatar Jan 19 '22 23:01 CharlesARoy

This is a tricky problem to solve because of the way Zsh completion works. I'll have to think what would be the best way to solve this.

marlonrichert avatar Jan 20 '22 13:01 marlonrichert

Thanks!

One way to pretty much fully fix this for me would be to add a widget-style option that causes Tab to work the way it does by default with Zsh. That way, in the above examples, I could use Tab to expand the share directory (or the tools directory) and use the arrow keys to select the suggested recent directories. In other words, I basically want to disable zsh-autocomplete from having anything to do with Tab. Let me know if that's unclear at all.

CharlesARoy avatar Jan 20 '22 18:01 CharlesARoy

I could use Tab to expand the share directory (or the tools directory) and use the arrow keys to select the suggested recent directories.

Have you tried just pressing Down Arrow on the command line? It lets you select which completion to insert.

But if you really want to use Tab for that, just add this to your .zshrc file:

zstyle ':autocomplete:tab:*' widget-style menu-select

Documented here: https://github.com/marlonrichert/zsh-autocomplete/blob/0b993ff7130dd33afecc365bb9edf5a330be842b/.zshrc#L44

marlonrichert avatar Jan 21 '22 07:01 marlonrichert

Sorry, I could have been clearer in my last message. In my original post, I raised two issues at the same time and probably should have created separate issues for them. For now, I can live with occasionally bad suggestions, as long as I can disable Tab from selecting the suggestion. In other words, I want Tab to work the standard Zsh way and only use arrow keys to select the zsh-autocomplete suggestions.

As I understand it, the current documentation supports:

  • "complete-word", in which Tab selects the top suggestion
  • "menu-complete", in which Tab cycles through the available suggestions without highlighting them and
  • "menu-select", in which Tab cycles through the available suggestions while highlighting them

image

I want Tab to be completely dissociated from zsh-autocomplete, is there a way to accomplish this?

Here's an example of why the currently available Tab options lead to super annoying situations relative to Zsh. Here's how things work without zsh-autocomplete: When I type cd ol<Tab> Zsh expands the directory tools, which actually has ol in it.

Zsh

Here's how things work with zsh-autocomplete: When I type cd ol for some reason it proposes the directory "lib", which makes no sense. Then when I hit Tab, lib gets expanded, which is infuriating. To reiterate, I can live with these kinds of bad suggestions, as long as Tab works normally and I exclusivley use arrow keys (or a key other than Tab) to cycle through the available suggestions.

Autocomplete

Thanks again for the help!

CharlesARoy avatar Jan 21 '22 18:01 CharlesARoy

Thanks for the extra explanation. That is indeed a problem. I will fix it when I have time. Or feel feel to submit a pull request.

marlonrichert avatar Feb 03 '22 15:02 marlonrichert

I've encountered a similar issue: image

Even thou my input starts with .loc, for some reason .docker is suggested first

zstyle ':autocomplete:*' fzf-completion yes
zstyle ':autocomplete:*' default-context ''
zstyle ':autocomplete:*' min-input 2
zstyle ':autocomplete:*' widget-style menu-select

ad-on-is avatar Feb 13 '22 18:02 ad-on-is

@ad-on-is I'm unable to reproduce that.

marlonrichert avatar Feb 20 '22 19:02 marlonrichert

@ad-on-is I'm unable to reproduce that.

Looks like the new update fixed it 👍

ad-on-is avatar Feb 20 '22 20:02 ad-on-is

@CharlesARoy I'm afraid this is not feasible without writing some very complex logic that I do not want to maintain. 😕 Instead of typing ar to get share.txt, try typing sar. 😉

marlonrichert avatar May 18 '23 16:05 marlonrichert