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

Show a message when no matching history items have been found

Open underlow opened this issue 1 year ago • 18 comments

  • [x] I have carefully read all of the instructions in this issue template.
  • [x] I have carried them out to the letter.

Failure to do so can and will result in your issue being closed without warning.

Environment

print $VENDOR $OSTYPE $SHELL $ZSH_ARGZERO $ZSH_PATCHLEVEL
print -l $_autocomplete__funcfiletrace
git -C ~zsh-autocomplete log --oneline -n1

apple darwin21.0 /bin/zsh -zsh zsh-5.8.1-0-g1a490c7
/Users/<user>/.zshrc:72
4c363ff (HEAD -> main, origin/main, origin/HEAD)
  • Operating system: macOS
  • Terminal emulator: iTerm2
  • [x] I have filled out the fields above.
  • [x] I have ran the commands in the code block above.
  • [x] I have pasted their output into the same block.

Steps to reproduce

cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
  • [x] I have run the code block above to create a test environment.
  • [x] I have reproduced my problem in this environment in the most minimal way possible.
  • [ ] I have copy-pasted my entire test session into the same code block.

So, initial issue is incorrect switching between history and completion mode

Now it works that way:

  • I type for example 'git' it shows history entries with git substring. image
  • After pressing Ctrl-R it switches to zsh-autosuggest (probably) with gray suggestion
image - And after Cmd-Space it switches to another mode (I don't know it's name) with command parameters suggestion image

But it should go straight to step 3 after pressing CtrlR on first step.

I can reproduce this issue using script above. But problem reproduces occasionaly

First attempt (everything works)

[/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.oL4cwVht]$ cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 58 (delta 0), reused 25 (delta 0), pack-reused 0
Receiving objects: 100% (58/58), 1.64 MiB | 2.87 MiB/s, done.
% zstyle ':autocomplete:*' default-context history-incremental-search-backward
% git
main porcelain command
add                -- add file contents to index
am                 -- apply patches from a mailbox
archive            -- create archive of files from named tree
bisect             -- find, by binary search, change that introduced a bug
branch             -- list, create, or delete branches
bundle             -- move objects and refs by archive
checkout           -- checkout branch or paths to working tree
cherry-pick        -- apply changes introduced by some existing commits
citool             -- graphical alternative to git commit
clean              -- remove untracked files from working tree
clone              -- clone repository into new directory
commit             -- record changes to repository
describe           -- show most recent tag that is reachable from a commit
diff               -- show changes between commits, commit and working tree, etc.

Second attempt (broken, CtrlR pressed on % git line)

[/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.KfnbHFDh]$ cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 58 (delta 0), reused 25 (delta 0), pack-reused 0
Receiving objects: 100% (58/58), 1.64 MiB | 2.80 MiB/s, done.
% zstyle ':autocomplete:*' default-context history-incremental-search-backward
% git
external command
git-receive-pack    git-shell           git-upload-archive  git-upload-pack
common substring: git-

my .zshrc : (aliases and commented lines removed)

export ZSH=/Users/mikhailov/.oh-my-zsh

ZSH_THEME="gallois"

plugins=(
    zsh-syntax-highlighting 
    git
    docker
	docker-compose 
	gradle
	brew
    httpie
    macos
	zsh-autosuggestions
    zsh-autocomplete
	spring
)

source $ZSH/oh-my-zsh.sh

source ~/.iterm2_shell_integration.zsh

export LC_ALL=en_US.UTF-8

export GPG_TTY=$(tty)

export PATH="/usr/local/bin:$PATH"
export PATH="/opt/homebrew/bin:$PATH"
export PATH="/usr/local/bin:$PATH"

HISTFILE="$HOME/.zsh_history"
HISTSIZE=10000000
SAVEHIST=10000000
setopt BANG_HIST                 # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY          # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY        # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY             # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST    # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS          # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS      # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS         # Do not display a line previously found.
setopt HIST_IGNORE_SPACE         # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS         # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS        # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY               # Don't execute immediately upon history expansion.
setopt HIST_BEEP                 # Beep when accessing nonexistent history.


zstyle ':autocomplete:*' default-context history-incremental-search-backward
zstyle ':autocomplete:*' insert-unambiguous yes

underlow avatar Aug 25 '22 09:08 underlow

How do you expect to find commands from history that start with git , if you don't have any of those in your history? But I could add a message that says something like "no matching history lines".

marlonrichert avatar Aug 25 '22 13:08 marlonrichert

I'm afraid there's some miscommunication. Everything's ok with history. Let me describe it once again.

  1. terminal starts in history mode.
  2. I press CtrlR
  3. I expect to see completion mode. But it's not wokring. Here is the problem.

Here is one more log: Here you can see that history works fine

[/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.QM7kO5GS]$ cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 58 (delta 0), reused 25 (delta 0), pack-reused 0
Receiving objects: 100% (58/58), 1.64 MiB | 2.86 MiB/s, done.
% git fetch
fatal: not a git repository (or any of the parent directories): .git
% git pull
fatal: not a git repository (or any of the parent directories): .git
%
2 git pull
1 git fetch

but if I press CtrlR I get this:

[/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.QM7kO5GS]$ cd $(mktemp -d)
git clone --depth 1 -- https://github.com/marlonrichert/zsh-autocomplete.git
> .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
source ~/zsh-autocomplete/zsh-autocomplete.plugin.zsh
EOF
env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
Cloning into 'zsh-autocomplete'...
remote: Enumerating objects: 58, done.
remote: Counting objects: 100% (58/58), done.
remote: Compressing objects: 100% (54/54), done.
remote: Total 58 (delta 0), reused 25 (delta 0), pack-reused 0
Receiving objects: 100% (58/58), 1.64 MiB | 2.86 MiB/s, done.
% git fetch
fatal: not a git repository (or any of the parent directories): .git
% git pull
fatal: not a git repository (or any of the parent directories): .git
% git
external command
git-receive-pack    git-shell           git-upload-archive  git-upload-pack
common substring: git-

but I expect this (it shows after pressing CtrlSpace:

% git
main porcelain command
add                -- add file contents to index
am                 -- apply patches from a mailbox
archive            -- create archive of files from named tree
bisect             -- find, by binary search, change that introduced a bug
branch             -- list, create, or delete branches
bundle             -- move objects and refs by archive
checkout           -- checkout branch or paths to working tree
cherry-pick        -- apply changes introduced by some existing commits
citool             -- graphical alternative to git commit
clean              -- remove untracked files from working tree
clone              -- clone repository into new directory
commit             -- record changes to repository
describe           -- show most recent tag that is reachable from a commit
diff               -- show changes between commits, commit and working tree, etc.

same behaviour you can fine on screenshots from original post. Also as you can see from original post it works from time to time. After pressing CtrlR you can see correct behaviour as well as incorrect

underlow avatar Aug 25 '22 14:08 underlow

% git
external command
git-receive-pack    git-shell           git-upload-archive  git-upload-pack
common substring: git-

Did you type a space after typing git? It looks like you haven't. That or the git (sub)command is taking a long time to complete. What happens if you type git  (with a space at the end) and then just wait a while?

marlonrichert avatar Aug 26 '22 06:08 marlonrichert

Did you type a space after typing git? It looks like you haven't.

Yes, I dit type space, you can see it here

I've tried with another command but in isolated environment I cannot get complete suggestions at all

image

That or the git (sub)command is taking a long time to complete. What happens if you type git (with a space at the end) and then just wait a while?

Nothing. I've waited for several minutes

underlow avatar Aug 26 '22 08:08 underlow

Yes, I dit type space, you can see it here

Your earlier example showed that completion strangely enough didn’t yet notice that you had typed a space:

% git external command git-receive-pack git-shell git-upload-archive git-upload-pack common substring: git-

But now you are showing that it did notice, but gives no completions at all. What is the difference in context between these two?

Please try the following:

  1. Add this to your .zshrc file after sourcing Zsh Autocomplete:
    bindkey '^Xh' _complete_help
    
  2. Whenever you feel that autocompletion (incl. history search) doesn’t show the right output, press Ctrl X and then H.
  3. Copy the output and paste it here.
  4. Also share what was on the command line and in which position the cursor was at that moment.

marlonrichert avatar Aug 27 '22 09:08 marlonrichert

Sorry, I've tried so many times with different settings so got messed up a bit.

But now you are showing that it did notice, but gives no completions at all. What is the difference in context between these two?

So to summarise. I try to reproduce issue in two different environments

  1. my iTerm with my .zsh in regular mode. Problem reproduces every time easily.
  2. isolated environment using your script. Problem reproduces 1 time of 5 tries.

in both cases problem reproduces equally, as shown on screenshots on initial post

This is output of CtrlX H on regular terminal after problem is reproduced:

[~]$ git
tags in context :completion::complete-fuzzy:git::
    argument-1 options  (_arguments _git)
tags in context :completion::complete-fuzzy:git:argument-1:
    aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands  (_git_commands _git)
tags in context :completion::complete-loose:git::
    argument-1 options  (_arguments _git)
tags in context :completion::complete-loose:git:argument-1:
    aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands  (_git_commands _git)
tags in context :completion::complete:git::
    argument-1 options  (_arguments _git _git)
tags in context :completion::complete:git:argument-1:
    aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands  (_git_commands _git _git)
image

I'll add info when I reproduce it on isolated env.

underlow avatar Aug 27 '22 10:08 underlow

One more thing. In regular terminal if I press CtrlR and history disappears second CtlrR will not bring it back. Maybe it's related somehow.

underlow avatar Aug 27 '22 10:08 underlow

Can you run the test session again, try reproducing the bug until it occurs, and then share the contents of the files $_autocomplete__log, $_autocomplete__log_async and $_autocomplete__log_pty here?

marlonrichert avatar Aug 29 '22 06:08 marlonrichert

Unfortunately cannot reproduce it anymore in test session, tried like 10 times. Would it be helpful to check these files on regular session? Problem reproduces there all the time

underlow avatar Aug 29 '22 08:08 underlow

Yes, please share the part of the logs corresponding to the moment the bug occurred.

marlonrichert avatar Aug 29 '22 11:08 marlonrichert

these file are in home directory, right? right after problem is reproduced two files are empty:

[~]$ cat $_autocomplete__log
.autocomplete.async.complete.fd-widget.inner:25: completion cannot be used recursively (yet)

[~]$ cat $_autocomplete__log_async

[~]$ cat $_autocomplete__log_pty
[~]$

underlow avatar Aug 29 '22 11:08 underlow

@underlow Can you try to find out what in your normal config causes the bug to occur?

marlonrichert avatar Sep 08 '22 06:09 marlonrichert

I'd love to but have no idea how. I've removed everything from .zshrc and problem still here. One thing I haven't done yet is full reinstall. If you have any idea what to check I definitely will check it

underlow avatar Sep 08 '22 11:09 underlow

Well, check what is the difference between your normal environment and the test environment. For example, check the output of env.

marlonrichert avatar Sep 08 '22 13:09 marlonrichert

I read your comments again and it looks like autocompletion is started correctly, but it never finishes. When the bug occurs, do you find that there are zombie zsh processes running?

marlonrichert avatar Sep 09 '22 05:09 marlonrichert

if I have 4 terminals open, reproduce problem in one of them then top |grep zsh in another shows 4 zsh processes.

underlow avatar Sep 09 '22 09:09 underlow

here is the diff between env

normal environment env (only differences)

TERM_SESSION_ID=w0t3p0:406CE152-9185-4CA3-961E-0E9ED68F7B34		HOME=/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.ijiqgcJs
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.w0XtO4ISFS/Listeners		
LC_TERMINAL_VERSION=3.4.16		
COLORFGBG=7;0		
ITERM_PROFILE=Default		
XPC_FLAGS=0x0		
PWD=/Users/user	
SHELL=/bin/zsh		
__CFBundleIdentifier=com.googlecode.iterm2		
LC_CTYPE=UTF-8		
TERM_PROGRAM_VERSION=3.4.16		
TERM_PROGRAM=iTerm.app

LC_TERMINAL=iTerm2		
COLORTERM=truecolor		
COMMAND_MODE=unix2003

HOME=/Users/user		
TMPDIR=/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/		
USER=user		
XPC_SERVICE_NAME=0

ITERM_SESSION_ID=w0t3p0:406CE152-9185-4CA3-961E-0E9ED68F7B34		
__CF_USER_TEXT_ENCODING=0x0:0:0

OLDPWD=/Users/user		PWD=/private/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.ijiqgcJs
ZSH=/Users/user/.oh-my-zsh		OLDPWD=/private/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.ijiqgcJs
PAGER=less		
LESS=-R		
LSCOLORS=Gxfxcxdxbxegedabagacad		
HOMEBREW_PREFIX=/opt/homebrew		
HOMEBREW_CELLAR=/opt/homebrew/Cellar		
HOMEBREW_REPOSITORY=/opt/homebrew		
MANPATH=/opt/homebrew/share/man::		
INFOPATH=/opt/homebrew/share/info:		
LC_ALL=en_US.UTF-8		
GPG_TTY=/dev/ttys003		
CONDA_EXE=/Users/user/miniconda3/bin/conda		
_CE_M=		
_CE_CONDA=		
CONDA_PYTHON_EXE=/Users/user/miniconda3/bin/python		
CONDA_SHLVL=1		
CONDA_PREFIX=/Users/user/miniconda3		
CONDA_DEFAULT_ENV=base		
CONDA_PROMPT_MODIFIER=(base)

test environment env (only differences)

TERM_SESSION_ID=w0t3p0:406CE152-9185-4CA3-961E-0E9ED68F7B34		HOME=/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.ijiqgcJs

PWD=/private/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.ijiqgcJs
ZSH=/Users/user/.oh-my-zsh		OLDPWD=/private/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/tmp.ijiqgcJs

I have no idea how to understand all these, maybe you can make a sense of it.

underlow avatar Sep 09 '22 09:09 underlow

How is it possible that ZSH=/Users/user/.oh-my-zsh gets set in your test environment? The shell session you pasted above did not include Oh-My-Zsh in the .zshrc file.

marlonrichert avatar Sep 19 '22 06:09 marlonrichert

Have no idea. Sorry, but I have literally zero knowledge about any zsh internals, just copy-paste commands and outputs.

Made diff once again and there is no such line.

normal env:

TERM_SESSION_ID=w0t2p0:F6E4FE93-BDEB-475C-A046-A5E37DAB72F4
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.w0XtO4ISFS/Listeners
LC_TERMINAL_VERSION=3.4.16
COLORFGBG=7;0
ITERM_PROFILE=Default
XPC_FLAGS=0x0
PWD=<path>
SHELL=/bin/zsh
__CFBundleIdentifier=com.googlecode.iterm2
LC_CTYPE=UTF-8
TERM_PROGRAM_VERSION=3.4.16
TERM_PROGRAM=iTerm.app
PATH=<path>
LC_TERMINAL=iTerm2
COLORTERM=truecolor
COMMAND_MODE=unix2003
TERM=xterm-256color
HOME=
TMPDIR=/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/
USER=
XPC_SERVICE_NAME=0
LOGNAME=
ITERM_SESSION_ID=w0t2p0:F6E4FE93-BDEB-475C-A046-A5E37DAB72F4
__CF_USER_TEXT_ENCODING=0x0:0:0
SHLVL=1
OLDPWD=
ZSH=
PAGER=less
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_REPOSITORY=/opt/homebrew
MANPATH=/opt/homebrew/share/man::
INFOPATH=/opt/homebrew/share/info:
LC_ALL=en_US.UTF-8
GPG_TTY=/dev/ttys000
CONDA_EXE=
_CE_M=
_CE_CONDA=
CONDA_PYTHON_EXE=
CONDA_SHLVL=1
CONDA_PREFIX=
CONDA_DEFAULT_ENV=base
CONDA_PROMPT_MODIFIER=(base)
_=/usr/bin/env

test env:

HOME=
PATH=<path>
TERM=xterm-256color
LOGNAME=
SHLVL=1
PWD=
OLDPWD=
_=/usr/bin/env

underlow avatar Sep 20 '22 07:09 underlow

I've removed everything from .zshrc and problem still here.

With a completely empty .zshrc file_ (so, no Zsh Autocomplete either), what is the output of env? If you then source Zsh Autocomplete, does the problem still occur? If you then run exec zsh -l -o sourcetrace, what output do you see?

marlonrichert avatar Sep 20 '22 15:09 marlonrichert

empty .zshrc

TERM_SESSION_ID=w0t0p0:AC77C214-B7EA-4695-95CE-B5498A171BD7
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.w0XtO4ISFS/Listeners
LC_TERMINAL_VERSION=3.4.16
COLORFGBG=7;0
ITERM_PROFILE=Default
XPC_FLAGS=0x0
PWD=
SHELL=/bin/zsh
__CFBundleIdentifier=com.googlecode.iterm2
LC_CTYPE=UTF-8
TERM_PROGRAM_VERSION=3.4.16
TERM_PROGRAM=iTerm.app
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
LC_TERMINAL=iTerm2
COLORTERM=truecolor
COMMAND_MODE=unix2003
TERM=xterm-256color
HOME=
TMPDIR=/var/folders/sy/fb43dhgn1dn61v690shrt9h80000gn/T/
USER=
XPC_SERVICE_NAME=0
LOGNAME=
ITERM_SESSION_ID=w0t0p0:AC77C214-B7EA-4695-95CE-B5498A171BD7
__CF_USER_TEXT_ENCODING=0x0:0:0
SHLVL=1
OLDPWD=
_=/usr/bin/env

If you then source Zsh Autocomplete, does the problem still occur?

No

If you then run exec zsh -l -o sourcetrace, what output do you see?

+/etc/zprofile:1> <sourcetrace>
+/Users/user/.zprofile:1> <sourcetrace>
+/etc/zshrc:1> <sourcetrace>
+/Users/user/.zshrc:1> <sourcetrace>

underlow avatar Sep 21 '22 08:09 underlow

If you then source Zsh Autocomplete, does the problem still occur?

Actually yes, but in other way. I'll look for a way to make video with keys pressed and get back

underlow avatar Sep 21 '22 08:09 underlow

I've checked several more times. No, problem does not appear with empty .zshrc

And the minimal config to reproduce issue is:

export ZSH=/Users/user/.oh-my-zsh

plugins=(
     zsh-autocomplete
)

source $ZSH/oh-my-zsh.sh

but it reproduces differently.

  1. turn on live history zstyle ':autocomplete:*' default-context history-incremental-search-backward
  2. type git a
  3. press CtrlR
  4. live history disappears and no completion appears
  5. type d (resulting line is git ad
  6. completion appears
  7. delete ad and type co
  8. no completion appears (but expected here)
  9. press CtrlSpace
  10. completion appears

I've highlighted with bold lines where I think behaviour is incorrect (items 4 and 8)

underlow avatar Sep 21 '22 12:09 underlow

I've removed oz-my-zsh and reinstalled it. same behaviour as in previous post

underlow avatar Sep 21 '22 12:09 underlow

Thanks for the additional info. Closing this as a duplicate of #483.

marlonrichert avatar Sep 21 '22 13:09 marlonrichert