Zsh-autosuggestions: The color of the automatic prompt is incorrect.

Created on 26 May 2020  路  12Comments  路  Source: zsh-users/zsh-autosuggestions

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

  • Expected behavior
    Expected

  • Current behavior
    Current

demo

Desktop

  • OS + distribution: macOS 10.15.2 (19C57) && Darwin 19.2.0
  • Zsh version: 5.7.1
  • Plugin version: ae315ded4dba10685dbbafbfa2ff3c1aefeb490d

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

# 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.

bug

Most helpful comment

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.

All 12 comments

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.

@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.

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

  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.

@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.

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 in the first place.

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.

@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

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.

  • Problem: when I shoot myself in the foot, it hurts.
  • Solution: don't.

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.

@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.

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

  • Theoretical question: Isn't it wrong that X happens when I run source ~/.zshrc?
  • Answer: No, it's not wrong. If you are using third-party code in ~/.zshrc, anything can happen when you run source ~/.zsrhc. There are no guarantees and no expectations. If you have expectations, you should forget about them.
  • Practical question: How do I reload zsh after changing configuration?
  • Answer: Run exec zsh.

If you could follow up by saying that exec zsh doesn't solve your practical problem, that would be once 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.

@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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mehedi-sharif picture mehedi-sharif  路  6Comments

moritzschaefer picture moritzschaefer  路  5Comments

hiteshsharma picture hiteshsharma  路  5Comments

srajasimman picture srajasimman  路  5Comments

clay-f picture clay-f  路  7Comments