zsh-users / zsh-autosuggestions

Fish-like autosuggestions for zsh
MIT License
30.99k stars 1.86k forks source link

The color of the automatic prompt is incorrect. #538

Open liby opened 4 years ago

liby commented 4 years ago

Describe the bug

After running the source .zshrc command, the color of the auto prompt is displayed incorrectly and is not grayed out.

To Reproduce

Steps to reproduce the behavior:

  1. Run source .zshrc command.
  2. Enter other commands to see tips

Expected behavior

The tips section should be gray.

Screenshots

demo

Desktop

Additional context

Although running the exec zsh command will make it display properly, but this does not completely solve the problem.Every time I run source .zshrc, it reproduces the incorrect display.

`.zshrc` file content ```shell # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. # Initialization code that may require console input (password prompts, [y/n] # confirmations, etc.) must go above this block; everything else may go below. if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" fi if [ -d "$HOME/bin" ] ; then PATH="$HOME/bin:$PATH" fi # Export Set export ZSH="$HOME/.oh-my-zsh" export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")" # Base Set COMPLETION_WAITING_DOTS="true" ENABLE_CORRECTION="true" # ZSH_DISABLE_COMPFIX="true" ZSH_THEME="powerlevel10k/powerlevel10k" # Plugins Set plugins=( autojump git zsh-autosuggestions zsh-completions zsh-syntax-highlighting ) autoload -U compinit && compinit # This loads nvm [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # Source Set source $ZSH/oh-my-zsh.sh # source ~/.bash_profile if [ -f ~/.bash_profile ]; then . ~/.bash_profile; fi [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh # Alias Set alias ll='ls -alFh' alias flushdns='sudo killall -HUP mDNSResponder' # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh ```

Other issues

By the way, how can plug-ins like this installed through git be updated? The install.md only says how to install through git, but does not tell me how to update.

ericfreese commented 4 years ago

Looks like a dup of https://github.com/zsh-users/zsh-autosuggestions/issues/516. Take a look there.

You can update plugins installed through git by running git pull (or any other git commands) in the cloned repo.

liby commented 4 years ago

@ericfreese Thank you for your reply. I thought that executing the upgrade_oh_my_zsh command would update all the plugins under the ~/.oh-my-zsh/custom/plugins path, but now it doesn't seem to be.

It was only when I created this issue yesterday that I updated the 'zsh-autosuggestions' plugin to the latest through the' git pull'', which was previously the code version in September 2019.

And a week ago, I didn't have this problem when I run source .zshrc. I don't know where the conflict is. But since I discovered the problem yesterday, whether it is the September 2019 version or the current latest version, there is this problem.

Now it seems that it can only be replaced by the exec zsh command. You can decide whether or not to close the question. Thank you again for your reply.

liby commented 4 years ago

I think I found out where the conflict is, When I was browsing #516, I find that we are all using powerlevel10k. I try to comment it out and then run source .zshrc and everything is fine.

@romkatv Maybe you can take a look at it for me. I'm really confused. I feel that replacing it with the exec zsh command is just a compromise and doesn't really solve the problem.

demo

romkatv commented 4 years ago
  1. Run source .zshrc command.

Don't. Use exec zsh if you want to reload zsh without starting a new process. It works better and takes fewer keystrokes.

liby commented 4 years ago

@romkatv Well, I'm sorry to bother you. Thank you. It's just that from a personal point of view, I'd like to know why they conflict.

romkatv commented 4 years ago

I'd like to know why they conflict.

I'm not aware of any conflict.

source ~/.zshrc evaluates ~/.zshrc for its side effects. If you run it twice, ~/.zshrc will be evaluated twice. The first evaluation starts from the clean slate. The second evaluation starts with the side effects from the first run already in place. In general anything with side effects is not idempotent, so in general evaluating ~/.zshrc twice is not equivalent to evaluating it once.

Instead of asking why running source ~/.zshrc sometimes breaks zsh, it's more appropriate to ask why would you expect it to work.

Another good question to ask is why you run source ~/.zshrc in the first place. If you want to restart zsh without creating a new process, use exec zsh. It's shorter, easier to type, and actually works.

liby commented 4 years ago

@romkatv

Did you notice the gif picture I sent above?

You can obviously see that if powerlevel10k is not enabled, running source ~/.zshrc does not cause any side effects with the 'zsh-autosuggestions' plugin. Everything looks normal.

But if powerlevel10k is enabled, then running the source ~/.zshrc command will cause the 'zsh-autosuggestions' plugin to display incorrectly. The color of the automatic prompt should have been gray.

If powerlevel10k is not enabled, no matter how many times you run source ~/.zshrc, it will not cause problems with the display of the' zsh-autosuggestions' plugin. So I said there was a conflict.

romkatv commented 4 years ago

@romkatv

Did you notice the gif picture I sent above?

Yes.

You can obviously see that if powerlevel10k is not enabled, running source ~/.zshrc does not cause any side effects with the 'zsh-autosuggestions' plugin. Everything looks normal.

When you run source ~/.zshrc, pretty much anything can happen. Sometimes this "anything" is nothing. Or it can appear to be nothing. Maybe your shell is a bit broken. Maybe it's a bit slower.

But if powerlevel10k is enabled, then running the source ~/.zshrc command will cause the 'zsh-autosuggestions' plugin to display incorrectly.

Anything can happen.

The color of the automatic prompt should have been gray.

No. Anything goes.

If powerlevel10k is not enabled, no matter how many times you run source ~/.zshrc, it will not cause problems with the display of the' zsh-autosuggestions' plugin.

OK.

So I said there was a conflict.

You are incorrect.

Here's an analogy.

If there was any reason for you to run source ~/.zshrc, then saying "don't" wouldn't be appropriate. There is no reason though, so just don't. You'll lose nothing if you stop running this command.

liby commented 4 years ago

@romkatv Maybe I'm a little obsessive-compulsive. Maybe our understanding of things seems to be fundamentally different.

You think there is a hidden danger in source ~/.zshrc, even if you can't see it now, you don't know when it will break out. So you think the best way is not to use it, and there's no reason to use it.

For the plugin 'zsh-autosuggestions' alone, what I care about is:

  1. Not Using powerlevel10k, running source ~/.zshrc is in good condition. Without discussing other hidden dangers, there is no problem with its use in terms of display alone.
  2. After enabling powerlevel10kand running source ~/.zshrc, the plug-in did not work as expected.

All I care about is why we don't have this obvious problem with the 'zsh-autosuggestions' plugin' if we don't enable powerlevel10k and run source ~/.zshrc.

Why when powerlevel10k is enabled, running source ~/.zshrc will cause the' zsh-autosuggestions' plugin to repeat the same problem over and over again. And I'm not the only one with the same problem.

We will not discuss other problems and hidden dangers of source ~/.zshrc here. The problem I see is that if powerlevel10k is not enabled, the 'zsh-autosuggestions' plugin will display normally after running source ~/.zshrc.

When powerlevel10k is enabled, running source ~/.zshrc, will cause the same problem with the 'zsh-autosuggestions' plugin'.

As expected, the rest of the commands it prompts should be light gray. But it shows that it is white. This problem can be stably reproduced. Then I think we should find out why.

And the reason is also found by the method of controlling variables, that is, with or without powerlevel10k enabled.

So I think it is irresponsible to simply and rudely attribute the problem to the source ~/.zshrc command.

romkatv commented 4 years ago

I think I've provided both the theoretical and the practical answer to your question.

If you could follow up by saying that exec zsh doesn't solve your practical problem, that would be one thing. But I don't see you making that argument.

So I think it is irresponsible to simply and rudely attribute the problem to the source ~/.zshrc command.

I'm sorry if you've found my direct answer rude. My goal is to be unambiguous. You are running source ~/.zshrc when you want to reload zsh. This goal can be achieved better by exec zsh. source ~/.zshrc is not supposed or meant to reload zsh and it doesn't reload zsh. Thus it shouldn't be used to reload zsh.

liby commented 4 years ago

@romkatv Well, I guess I see what you mean. What I'm obsessed with is why there is such a problem, and you think it's nothing to worry about, and it's not surprising that it's so bad that it leads to any problems.

romkatv commented 4 years ago

Indeed. Shooting yourself in the foot can cause problems. One could be curious under which conditions this pointless and dangerous exercise is less or more painful. Investigating this isn't productive use of anyone's time though.

warren-lei commented 3 years ago

I think it is a problem of terminal, try to export TERM=xterm-256color. I have solved this problem by this way.

liby commented 3 years ago

@warren-lei

I tried. It didn't solve the problem. I don't know if you can tell the difference.

https://user-images.githubusercontent.com/38807139/126740559-4ef0e07f-19ee-489b-8e9b-70d63f54969a.mp4

Chattille commented 2 years ago

516 worked for me.

I use zsh-syntax-highlighting and zsh-autosuggestions at the same time. I had the same issue, except that it happened all the time irrespective of whether I used exec zsh or source ~/.zshrc, but it worked normally after I commented out the highlighting plugin. It turns out that the plugin have not been updated for quite a long time. The problem was gone after I updated zsh-syntax-highlighting.

gfsd3v commented 2 years ago

516 worked for me. I use zsh-syntax-highlighting and zsh-autosuggestions at the same time. I had the same issue, except that it happened all the time irrespective of whether I used exec zsh or source ~/.zshrc, but it worked normally after I commented out the highlighting plugin. It turns out that the plugin have not been updated for quite a long time. The problem was gone after I updated zsh-syntax-highlighting.

This was my case, thanks for posting the solution :+1:

liby commented 2 years ago

Oh, this issue is so long ago that I have forgotten the specifics of the time. When I saw @Chattille reply, I really thought the problem was solved (maybe). In fact, in the beginning of the discussion, we have already tried the method of updating the zsh-syntax-highlighting plugin, which is the solution mentioned in #516. The result is that if you use p10k, this solution does not work and you can only use the exec zsh command instead of source ~/.zshrc.

TL;DR

https://user-images.githubusercontent.com/38807139/155459595-fa3468b4-b3ee-43cc-85ca-c86fb6fe27c4.mp4

romkatv commented 2 years ago

When I saw @Chattille reply, I really thought the problem was solved (maybe).

As far as I'm concerned it was solved.

The result is that if you use p10k, this solution does not work and you can only use the exec zsh command instead of source ~/.zshrc.

The solution is to never run source ~/.zshrc. It doesn't matter whether you are using p10k or not.

TL;DR

The TL;DR is to not run source ~/.zshrc. Use exec zsh instead.

tnfru commented 2 years ago

Now I solved this by updating the autosuggestion plugin, but quite discussion here. Since exec zsh seems to be the proper way to source things, can you detail how it would look to source P10k?

In my .zshrc file when sourcing p10k config file should it be exec patch/to/config/file ?

romkatv commented 2 years ago

Since exec zsh seems to be the proper way to source things, can you detail how it would look to source P10k?

In my .zshrc file when sourcing p10k config file should it be exec patch/to/config/file ?

Put source commands in ~/.zshrc to source files. Use exec zsh to restart zsh after making changes to ~/.zshrc. You can also close your terminal and reopen it instead of running exec zsh.

mrleblanc101 commented 6 months ago

I also have an issue with the color, I also have p10k, but the issue is still there when I disable p10k. My highlight is red to make the problem more evident. As I type, the nightlight disappear and reappear and I can't seem to figure out why.

Here are my plugins:

plugins=(
    zsh-history-substring-search
    zsh-autosuggestions
    git
    git-open
    docker
    nvm
    npm
    yarn
)
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=9"
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
bindkey '^[OC'   vi-forward-blank-word

2024-02-28 16 45 00

mrleblanc101 commented 6 months ago

This issue is when I enable zsh-history-substring-search, I'll post the solution if I find it

mrleblanc101 commented 6 months ago

I have added this to my zshrc:

bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down

Not sure why this was required as this seems to be the default