-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tab completion incorrectly completes the wrong file when starting with the end of the filename #212
Comments
I think the current behavior makes sense. It won't bring up the tab complete menu in line two of your second code block because the test of "is valid file under cursor, or can we complete to one" passes on the first condition. This applies to the third code block as well. For sake of completion, you're expecting it to behave as below: $ touch foo-chem-bar && rm foo-bar
$ touch -bar<tab>
$ touch foo--bar
^ cursor here
-- file --
foo-baz-bar foo-chem-bar Notice the removal of Your example doesn't work because it completes that to the prefix of the possible options ("foo"), and then performs the "is this a valid entry" test when you hit tab the second time, which passes. |
Yes, your code block is what I'm expecting. IMO merely passing "is this a valid entry" test shouldn't cause tab to move on, to the end of the line. Instead, I think it should be "is this the only valid entry". Otherwise, how would you ever get to select/complete In addition, the current behaviour is still different to when you start typing from the beginning of the string. In the following example, the two files have the same beginning. After the second
|
Hm. I'm not sure what would need to be changed to meet your expectations of behavior of the shell. This is one of those quirks where I'm not sure where the "fix" needs to be. |
I'm not sure if you mean you are not sure what part of the code to change, or what end behaviour to change? If the latter, then my primary expectation would be as follows.
Thinking about it a bit more, that's probably the problem with the current implementation. As per the second code block above:
I'm not sure what the resolution is programmatically. Is there no way to "record" the type of auto-completion in the first line? Or could auto-completion behave differently if the cursor is located in the middle of the string, at an ambiguous location? |
I meant what zstyle or other options need to be changed to provide the behavior you expect. |
Oh. Right. Apologies for the misinterpretation. |
@protist, the Completion and expansion title in Chapter 6 of the Z-Shell Guide has:
TL;DR: Typing
@protist, it the behavior you're looking for between these 3 options here? |
@protist,
|
@ericbn That looks ideal from your example, but it doesn't seem to work for me. It still has the same behaviour as prior to changing that setting. i.e. it still fully completes the word.
EDIT: this is with the minimal config from the first post. |
Thank you @ericbn. That commit works perfectly! Now the behaviour is as follows.
And a subsequent tab can select from the menu. This is great, and no longer automatically completes. Just for the record, the cursor position was slightly unintuitive at first. Previously, it was at the Thanks again! |
@protist, I also think it behaves better now. But having just fuzzy matching is giving me too many matches, as I usually want to match from the beginning of the name. So maybe having zsh first try to match from the beginning, and then (if there's no match) try to do the fuzzy match is a better configuration. All case insensitive, of course. Agree? @Eriner, thoughts? |
I haven't really noticed anything annoying yet personally, but I think I probably agree with you conceptually. Presumably, if you have |
Done. Thanks again for your input, @protist. |
No worries @ericbn. Thank you for the quick fixes and responsiveness! Unfortunately though, the behaviour of your latest commit is essentially back to where we started!
The second |
It works for me: (asciinema recording). I'm on the latest commit. |
@AtomicCoding I don't think you are testing the same thing, but it's hard to tell without knowing your directory's contents. In your example, create another file called |
@protist Sorry! Misunderstood! |
@AtomicCoding No worries. Thanks for the interest though! |
@AtomicCoding Huh, nice. Yes, that's exactly how it should behave IMO. Which commit are you using? I just updated to master (13eb86d), but I'm still seeing the same behaviour as before. |
@AtomicCoding, I cannot reproduce your last video recording with My zim is also updated to master (13eb86d), and I tried it with zsh 5.3 and zsh 5.5. |
@ericbn @protist
setopt alwaystoend autocd autopushd autoresume nobgnice nocaseglob nocheckjobs noclobber completeinword correct extendedglob extendedhistory globcomplete histignorealldups histignoredups histignorespace histsavenodups histverify nohup incappendhistory interactive interactivecomments nolistbeep login longlistjobs menucomplete pathdirs promptsubst pushdignoredups pushdsilent pushdtohome sharehistory shinstdin
zmodules=(directory environment git git-info history input utility brobot \
brew prompt completion colors bd \
osx notify python directory 256color interactive-cd \
autosuggestions syntax-highlighting history-substring-search) Seems to be the plugins I have loaded, removing all my custom plugins seemed to change it back to the incorrect behavior. Maybe they change zim's completion config or rebind things? |
@AtomicCoding What happens if you move |
@Eriner Still works. I did some testing and it seems to be my custom plugin |
@Eriner @ericbn @protist Can you try setting
Opened PR, #264 |
Doing |
@ericbn Was this meant to be closed? The referenced commit was an old one, right? And has subsequently been modified anyway? |
I think this still needs to be fixed, and that the current configuration we have is not good enough. |
@Eriner, I'm divided here after the long discussion that happened around this issue. I'm not happy with the current
All above are case-insensitive. Only the first one matches from the beginning first. I wish I could make the last one to that, but I could not. ... Or maybe something else that works? |
Does there need to be one chosen? Can you maybe make this configurable? Along with this excellent explanation the end user can then make his own decision. |
@edwardsmit You can just put the relevant @ericbn I've actually lost track a bit of which configs we've tried before. I tested the suggestions in a new directory after
(Actually, this fails similarly to some other code previously in this thread.) |
@protist, here I am back with another "trial". :- ) I found an issue in unix.stackexchange like yours. I tried the first answer and got satisfactory results with it. It's not fuzzy matching, but completes from the beginning first, then from middle or end. The original answer suggests:
which should be the equivalent of:
And a case-insentivite variation should be:
I'm using the last one above and could not break it with any of the tests we've been making here. Can you please try too? |
@ericbn |
Huh, what a startling coincidence! 😲 However, I tried all three variants, but for me they still fail as per the original post. Firstly,
|
@protist, I get mixed results depending on if I try to complete from Given we're on an empty directory and then
By "Good" I mean offering both files in the completion menu. By "Bad" I mean completing to Tried with zsh 5.3 and zsh 5.5.1 running on MacOS 10.13.4 (Mac), and zsh 5.4.2 running on Ubuntu 16.04.3 on Linux Subsystem for Windows (PC). |
@ericbn Thanks for that extremely thorough troubleshooting! I'm on Linux with zsh 5.5.1. I have no idea why the same version of zsh would produce different results on Mac and Linux. Seems very odd. I also tried the first zstyle with |
@protist, the partial completion to I get all kinds of different completions depending of the OS or zsh version I'm in. I just classified as "Bad" when I don't get the completion menu, and "Good" when I do get it (no matter how many tabs I have to press). |
@ericbn Sorry for the delay; I've been quite ill. Your explanation makes sense. I actually don't feel strongly about how much gets completed, as long as the completion menu appears after. The only reason I mentioned it was because I thought it might be diagnostic for why/when "Bad"ness and "Good"ness occurs. I also find it bizarre that this difference exists between Mac and Linux. |
Thanks @ericbn! Tested and works well. I went through the same testing above, and it all works as expected. Thank you for persisting and well done on fixing this! |
Oh no @ericbn! Sorry, it's still buggy. From above, I think we agreed that zsh should attempt to match from the beginning of the word first, and only if that failed to use the "fuzzier" matching. However, this doesn't seem to be the case.
The first tab only completes to bar, and the second tab will show the selection menu. I think our previous thoughts were that the first tab should immediately complete to |
Just reverted the commit. Back to the drawing board... |
I've been coming across weird ones every now and then. This was a particularly weird one today.
The word starting with |
Hi @protist. Looks like this is an issue with Zsh 5.9 when using |
Thanks @ericbn. Nice find. I tested the patch, and it does indeed fix that latest issue. |
@protist, what about using Another option would be using:
It first shows the completion options on the first tab and then completes on the second tab. The drawback of this option is that is lists even when there's only one completion option. |
Thanks @ericbn. Honestly, I think either option is not as good as the current version. I do like being able to tab-complete as much as possible, then to type the rest of the filename. This seems the quickest workflow. As an example, I might want to specify a number of files with a similar prefix. e.g.
which will complete to With |
@protist, thanks for the feedback. Good point, I agree the partial completions are a nice to have. Both options I proposed were getting rid of them. Not having partial completions fixes some of issues here, since the completion system won't have to pick up from those partial completions. If only we could make them cleaner. |
Please check the existing issues to make sure you're not duplicating a report.
For bug reports, please provide the following information:
In a terminal, run
zmanage info
and paste the output below:But I'm running the zim master via Arch Linux AUR's zsh-zim-git: 9eaba9a
zmodules=(completion)
source /usr/lib/zim/init.zsh
Description
Tab completion incorrectly fully completes the wrong file when starting with the end of the filename.
Steps to reproduce
Tab completion works fine if starting from the start of the filename.
However, if I start typing from the back (or middle) of the filename, it fails.
I would expect the second tab to bring up the completion-selection menu. However, it immediately completes to the shorter version instead.
Another slightly different case is if I type the entirety of the shared string.
In this case, I'm not even given the cursor in the middle, it jumps straight to the end.
The text was updated successfully, but these errors were encountered: