zsh-users / zsh-syntax-highlighting

Fish shell like syntax highlighting for Zsh.
github.com/zsh-users/zsh-syntax-highlighting
BSD 3-Clause "New" or "Revised" License
19.5k stars 1.32k forks source link

Highlights red after path autocompletion #912

Closed RegreTTO closed 1 year ago

RegreTTO commented 1 year ago

When I type some path beginning it is highlighted by red as it should be, but after I use autocomplete, typed part is still red while the rest part of the path is highlighted normally

изображение

In this example I've typed ~/.oh-my-zsh/ manually and then invoked autocomplete

phy1729 commented 1 year ago

My best guess would be autocomplete is sourced after z-sy-h, so z-sy-h can't wrap that key bind. Please double check the order plugins are sourced.

RegreTTO commented 1 year ago

I've put this plugin on the top of the others, but it hasn't helped

RegreTTO commented 1 year ago

This is a part from my .zshrc

# ZSH Highlighting settings
typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[default]='fg=cyan'
ZSH_HIGHLIGHT_STYLES[path]='underline, standout'
ZSH_HIGHLIGHT_STYLES[builtin]='fg=#65c7c4, bold'
ZSH_HIGHLIGHT_STYLES[command]='fg=#65c7c4, bold'
ZSH_HIGHLIGHT_STYLES[alias]='fg=#65c7c4, bold'

ZSH_THEME="bira"
plugins=(
  zsh-syntax-highlighting
  git
  gitignore
  zsh-autosuggestions
  virtualenv
  copyfile
  interactive-cd
  z
)
phy1729 commented 1 year ago

z-sy-h should be last not first. See https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md#oh-my-zsh

RegreTTO commented 1 year ago

Unfortunatelly after moving it down nothing's changed

danielshahaf commented 1 year ago

I think this can't be caused by using z-sy-h on top of zsh -f, so we'll have to close this as unreproducible unless someone comes up with a reproduction recipe.

AndreasBackx commented 1 year ago

I have a similar issue, when typing sud, the zsh-autosuggestions plugin suggests my last command which is sudo dnf install difftastic:

image

When pressing the right arrow to autocomplete it, completes it properly but the syntax highlighting is incorrect:

image

Meanwhile while typing it manually in its entirety does show it properly:

image

Pressing the right arrow shows where you pressed it if you do it midway through:

image

My dotfiles are here: https://github.com/AndreasBackx/dotfiles. In my latest commit as of writing I move the plugin to the end, but that does not seem to make a difference. If I can help make a reproducible sample, I would love to try but don't know how right now. I have this problem on at least 2 machines, perhaps 3. Definitely 1 Fedora 37 and 1 Arch Linux machine, possibly 1 other Fedora 37 machine that I cannot test right now.

Let me know if there's something else I can provide.

danielshahaf commented 1 year ago

If I can help make a reproducible sample, I would love to try but don't know how right now.

In short: run zsh -f and therein: use the source builtin to load the relevant plugins (as few as possible, of course); run echo or true or : with some arguments to populate history; type another command (and possibly press [Tab] or [→] or whatever) to reproduce the problem. Also, include the commit hashes of everything, don't just say "latest". Thanks :)

gashnya commented 1 year ago

Same problem after upgrading from Ubuntu 22.04 to 22.10.

As @danielshahaf suggested, I tried to sequentially source plugins in no-rcs mode and check at every step if the problem appears:

zhenya% source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.plugin.zsh
zhenya% source ~/.zsh/colorize/colorize.plugin.zsh
zhenya% source ~/.zsh/zsh-command-not-found/command-not-found.plugin.zsh
zhenya% source ~/.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh

At this point everything works as it worked before (I suppose, the right color for suggestions is grabbed from my terminal colors).

Screenshot_2023-01-29_19-43-27 Screenshot_2023-01-29_19-44-10

So, I tried another line from my .zshrc:

zhenya% ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#7F7864'

After that, accepted suggestions began to be highlighted incorrectly.

Screenshot_2023-01-29_19-44-56 Screenshot_2023-01-29_19-45-20

Removing this line from .zshrc solved the problem for me. But, interestingly, setting another color also corrects highlighting:

zhenya% ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#777777'

Screenshot_2023-01-29_19-47-15 Screenshot_2023-01-29_19-48-18

Additionally, I noticed that everything works fine with hex colors without letters. Hope, this will be useful for somebody.

AndreasBackx commented 1 year ago

In short: run zsh -f and therein: use the source builtin to load the relevant plugins (as few as possible, of course); run echo or true or : with some arguments to populate history; type another command (and possibly press [Tab] or [→] or whatever) to reproduce the problem. Also, include the commit hashes of everything, don't just say "latest". Thanks :)

@danielshahaf

So running zsh -f I can reproduce it as follows:

$ plugins=(zsh-autosuggestions zsh-syntax-highlighting)
$ source $HOME/.oh-my-zsh/oh-my-zsh.sh
$ echo 1

Then typing echo and right arrow will lead to the bug.

image

Without oh-my-zsh and sourcing the files directly also leads to the problem so it seems to be unrelated to oh-my-zsh?

image

What @gashnya says I can reproduce as well.

image

Thus if I set it to my default, it fixed it for me.

image

AndreasBackx commented 1 year ago

Just after writing this previous comment I noticed that I have the following in my dotfiles:

export ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=0"

Turns out that was the problem for me. Just removing that fixes the problem.

It turns out that setting that explicitly makes for the bug...

It does so for explicit colour numbers:

image

And for hex codes:

image

Fixed it in my dotfiles here: https://github.com/AndreasBackx/dotfiles/commit/4c14884a9f5b5d4297f52bfe898f7a7ce77b0c97

danielshahaf commented 1 year ago

Thanks for the additional information.

I'd like to repeat that I requested minimal reproduction recipes, involving as few external dependencies as possible. That means one external plugin is better than three, and without omz is better than with.

Anyway, I can reproduce this now using

To reproduce:

$ zsh-5.9 -f
% bindkey -e
% . ./asug
% . ./zsyh
% ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#FF00FF'
% echo true
true
% echo «press Ctrl+E»
true

Note that this only reproduces with uppercase hex digits (!). With lowercase hex digits it's fine.

danielshahaf commented 1 year ago

"Reproduces" means that the stuff added by the press of Ctrl+E is in #FF00FF rather than in whatever colour z-sy-h would have it.

danielshahaf commented 1 year ago

Duplicate of https://github.com/zsh-users/zsh-autosuggestions/issues/698; see Oliver's comments there for the recommended solution (tl;dr z-asug should use the memo= feature of zsh≥5.9).

To be clear, this isn't a bug in z-sy-h.