marlonrichert / zsh-autocomplete

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

Tab autocompletion picks first item instead of the longest common prefix #457

Closed amomchilov closed 2 years ago

amomchilov commented 2 years ago

Environment

apple darwin22.0 /bin/zsh -zsh zsh-5.8.1-0-g1a490c7
/Users/Alex/.zshrc:139
f52f45a (HEAD -> main, origin/main, origin/HEAD, my_fork/main) Change precmd to chpwd for zlua

Steps to reproduce

cd $(mktemp -d)

git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git

# Default config from the issue tempalte:
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF

# Extra config step for repro:
echo "zstyle ':autocomplete:*' insert-unambiguous yes" >> ./.zshrc

env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d

# (new subshell opened)

mkdir Downloads Documents Drive

# Started typing without pressing enter. Auto-comletion prompt shown below.
# Tabbing at this point completes to "Documents/", despite the `insert-unambiguous yes` above
cd D
# directory
# Documents/  Downloads/  Drive/
# <no mention of "common substring:">

# Typed "o" without pressing enter. Auto-comletion prompt shown below.
# Tabbing at this point completes to "Documents/", despite the `insert-unambiguous yes` above
cd Do
# directory
# Documents/  Downloads/
# <still no mention of "common substring:">

# Confirming that the style setting is really set:
zstyle -L | grep "unambig"
# zstyle ':autocomplete:shift-tab:*' insert-unambiguous yes
# zstyle ':autocomplete:*' insert-unambiguous yes

With cd D in the prompt, pressing tabs expands to the first item (aaaaaaab) instead of the common substring (aaaaaaa)

zstyle -L output ``` zstyle ':completion:*:expand:*' accept-exact continue zstyle :bracketed-paste-magic active-widgets 'self-*' zstyle ':completion:*:expand:*' add-space subst zstyle ':completion:*' auto-description %d zstyle -e ':completion:*' cache-path _autocomplete.config.cache-path zstyle ':completion:*:*:*:*:processes' command 'ps -u alex -o pid,user,comm -w -w' zstyle ':completion:*' command '- COLUMNS=999' zstyle ':completion:*:expand-alias:*' complete yes zstyle ':completion:*' complete-options yes zstyle ':completion:list-expand:*' completer _expand _complete:-fuzzy _ignored zstyle ':completion:history-incremental-*search-*:*' completer _autocomplete.history_lines zstyle -e ':completion:*' completer _autocomplete.config.completer zstyle ':completion:*:paths' expand suffix zstyle ':completion:*:parameters' extra-verbose yes zstyle -e ':completion:*:-command-:*' file-patterns _autocomplete.config.file-patterns.command zstyle ':completion:*:(.|source):*' file-patterns '%p(#q-/):directories:directory %p~*.zwc(-.^*):globbed-files' '%p~*.zwc(-^/):globbed-files' zstyle ':completion:*' file-patterns '*(-/):directories:directory %p(#q^-/):globbed-files' zstyle ':completion:*:descriptions' format $'%{\C-[[0;2m%}%d%{\C-[[0m%}' zstyle -e ':completion:*:warnings' format _autocomplete.config.format zstyle ':completion:*:messages' format '%F{9}%d%f' zstyle ':completion:*:history-lines' format '' zstyle -e ':completion:*:expand:*' glob _autocomplete.is_glob zstyle ':completion:*' group-name '' zstyle ':completion:*' group-order expansions options aliases suffix-aliases functions reserved-words builtins commands local-directories directories executables zstyle -e ':completion:*:(ssh|scp|sftp|rsh|rsync):hosts' hosts 'reply=(${=${${(f)"$(cat {/etc/ssh_,~/.ssh/known_}hosts(|2)(N) /dev/null)"}%%[# ]*}//,/ })' zstyle ':completion:*:-command-:*' ignore-line current zstyle ':completion:*' ignore-parents 'parent pwd directory' zstyle ':completion:*:*:*:users' ignored-patterns adm amanda apache at avahi avahi-autoipd beaglidx bin cacti canna clamav daemon dbus distcache dnsmasq dovecot fax ftp games gdm gkrellmd gopher hacluster haldaemon halt hsqldb ident junkbust kdm ldap lp mail mailman mailnull man messagebus mldonkey mysql nagios named netdump news nfsnobody nobody nscd ntp nut nx obsrun openvpn operator pcap polkitd postfix postgres privoxy pulse pvm quagga radvd rpc rpcuser rpm rtkit scard shutdown squid sshd statd svn sync tftp usbmux uucp vcsa wwwrun xfs '_*' zstyle ':completion:*:users' ignored-patterns '_*' zstyle ':completion:*:widgets' ignored-patterns '.*' '*:*' '*orig-*' zstyle ':completion:*' insert-sections yes zstyle ':autocomplete:shift-tab:*' insert-unambiguous yes zstyle ':autocomplete:*' insert-unambiguous yes zstyle ':completion:*:expand:*' keep-prefix no zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' zstyle ':completion:*' list-colors '' zstyle ':completion:*:paths' list-suffixes yes zstyle ':completion:*:options' matcher 'b:-=+' zstyle ':completion:*-loose:*' matcher-list 'm:{[:lower:]-}={[:upper:]_} r:|[.]=** l:?|=[-_\\ ] r:?||[-_]=*' zstyle ':completion:*-fuzzy:*' matcher-list 'm:{[:lower:]-}={[:upper:]_} r:|?=**' zstyle ':completion:*' matcher-list 'm:{[:lower:]-}={[:upper:]_} r:|[.]=**' '+l:|=*' zstyle ':completion:*:paths' path-completion no zstyle ':completion:*' prefix-needed yes zstyle ':chpwd:*' recent-dirs-file /Users/alex/.local/share/zsh/chpwd-recent-dirs zstyle ':chpwd:*' recent-dirs-max 0 zstyle ':completion:*:default' select-prompt '%F{black}%K{14}line %l %p%f%k' zstyle ':completion:*' separate-sections yes zstyle -e ':completion:*:expand:*' substitute _autocomplete.config.expand.substitute zstyle ':completion:list-expand:*:-command-:*' tag-order '*' zstyle ':completion:list-expand:*:git-*:(|*-)argument-*:*' tag-order '*' zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories zstyle ':completion:*:expand:*' tag-order '! all-expansions original' - zstyle -e ':completion:*:-command-:*' tag-order _autocomplete.config.tag-order.command zstyle ':completion:*:-tilde-:*' tag-order directory-stack named-directories zstyle ':completion:*:git-*:(|*-)argument-*:*' tag-order '! (|cached-)files *-remote remote-* (|*-)tags' '! *-remote remote-* tags' zstyle ':completion:*:(approximate|correct):*' tag-order '! original' - zstyle zle-hook types isearch-exit isearch-update line-pre-redraw line-init line-finish history-line-set keymap-select zstyle -e :url-quote-magic url-globbers $'zmodload -i zsh/parameter;\n\t reply=( noglob\n\t\t ${(k)galiases[(R)(* |)(noglob|urlglobber|globurl) *]:-}\n\t\t ${(k)aliases[(R)(* |)(noglob|urlglobber|globurl) *]:-} )' zstyle :urlglobber url-local-schema ftp file zstyle ':url-quote-magic:*' url-metas '*?[]^(|)~#{}=' zstyle :urlglobber url-other-schema http https ftp zstyle -e ':url-quote-magic:*' url-seps 'reply=(";&<>${histchars[1]}")' zstyle ':completion:*' use-cache yes zstyle ':autocomplete:tab:*' widget-style complete-word zstyle ':autocomplete:shift-tab:*' widget-style complete-word zstyle zle-line-init widgets 0:user:zle-line-init 1:.autocomplete.async.read-cursor-position 2:.autocomplete.async.reset-context 3:.autocomplete.async.complete zstyle zle-line-pre-redraw widgets 1:.autocomplete.async.complete zstyle zle-line-finish widgets 0:user:zle-line-finish 1:.autocomplete.async.clear zstyle zle-isearch-update widgets 1:.autocomplete.async.isearch-update zstyle zle-isearch-exit widgets 1:.autocomplete.async.isearch-exit ```
CraigSiemens commented 2 years ago

I've got the same issue when using Terminal.app.

marlonrichert commented 2 years ago

You need to add this to your .zshrc file, but set it to yes: https://github.com/marlonrichert/zsh-autocomplete/blob/d8bfbef46efc54c1189010a3b70d501b44487504/.zshrc#L38

See that file for a full list of config options.

amomchilov commented 2 years ago

Hmmm I think I've gotten stuff big-time mixed up in this bug report. I was trying to capture the issue from https://github.com/marlonrichert/zsh-autocomplete/discussions/453. I've got my signals crossed between an example that used Documents, Downloads,Drive with one that used aaaaaaab and aaaaaaac.

I've updated the description with a correct and clearer set of repro steps, which I've carefully confirmed is definitely bugged (for me, at least).

marlonrichert commented 2 years ago
# Started typing without pressing enter. Auto-comletion prompt shown below.
# Tabbing at this point completes to "Documents/", despite the `insert-unambiguous yes` above
cd D
# directory
# Documents/  Downloads/  Drive/
# <no mention of "common substring:">

# Typed "o" without pressing enter. Auto-comletion prompt shown below.
# Tabbing at this point completes to "Documents/", despite the `insert-unambiguous yes` above
cd Do
# directory
# Documents/  Downloads/
# <still no mention of "common substring:">

In both of these cases, the longest common substring that can be completed from the current word on the command is equal to the current word on the command line. So, there’s no substring to insert there. That’s why it doesn’t get mentioned

What were you expecting to be inserted in those cases?