marlonrichert / zsh-autocomplete

🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.
MIT License
5.38k stars 148 forks source link

wrong common substring in tab completion #612

Closed galkk closed 1 year ago

galkk commented 1 year ago

In a directory with following files % 1-minimal.sh 2-minimal-config.sh 3-full.sh 4-gui-fonts.sh 4-gui.sh 5-personal.sh 6-personal-gui.sh Dockerfile docker-compose.yml

when entered ./4-, the zsh-autocomplete shows ./4-gui.sh as common substring, while I expect it to be truly common substring: ./4-gui.

Issue reproduces with both my config (that has zstyle ':autocomplete:*' insert-unambiguous yes), and config in "steps to reproduce" section

Environment

❯ typeset -p1 VENDOR OSTYPE ZSH_PATCHLEVEL _autocomplete__funcfiletrace
typeset VENDOR=ubuntu
typeset OSTYPE=linux-gnu
typeset ZSH_PATCHLEVEL=ubuntu/5.8.1-1
typeset -a _autocomplete__funcfiletrace=(
  /home/andy/.znap/marlonrichert/zsh-autocomplete/zsh-autocomplete.plugin.zsh:4
  /home/andy/.zshrc:34
  /home/andy/.znap/znap/functions/.znap.source:37
  /home/andy/.znap/znap/functions/znap:27
  /home/andy/.zshrc:15
  zsh:0
)
❯  git -C ~autocomplete log --oneline -n1
93df12e (grafted, HEAD -> main, origin/main, origin/HEAD) Add `_complete_help` keybinding
<output>

Steps to reproduce

cd $(mktemp -d)
❯  git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 55, done.
remote: Counting objects: 100% (55/55), done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 55 (delta 0), reused 31 (delta 0), pack-reused 0
Receiving objects: 100% (55/55), 1.64 MiB | 16.76 MiB/s, done.
❯  > .zshrc <<EOF
setopt interactivecomments transientrprompt
PS1='%# '
PS2=
RPS2='%^'
source $PWD/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
❯  env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d

% cd /home/andy/projects/dotfiles/setup 
% ls
1-minimal.sh  2-minimal-config.sh  3-full.sh  4-gui-fonts.sh  4-gui.sh  5-personal.sh  6-personal-gui.sh  Dockerfile  docker-compose.yml
% ./4-
executable file
4-gui-fonts.sh*  4-gui.sh*      
common substring: ./4-gui.sh
Contents of ~autocomplete-log/YYYY-MM-DD.log (click to expand): file is empty
> cat ~autocomplete-log/2023-07-03.log

marlonrichert commented 1 year ago

"Common substring" is not entirely accurate to describe what will be inserted. Rather, it's the longest input that would complete to all listed completion. If you can think of a better phrase to describe this, I'm all ears.

In any case, this is expected behavior in Zsh. See also https://github.com/marlonrichert/zsh-autocomplete/issues/602#issuecomment-1603103847.