4

I have installed zsh-autosuggestions plugin in oh-my-zsh.
I'd like to change the colour of the text which comes in suggestion. My current color is very similar to that of what comes before.

Please see the image below.

enter image description here

This setting is probably govern by ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE setting. But when I add e.g. ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=60' the following happens:

enter image description here

What I'd like to have is bin in much different color than cd.

3
  • The behaviour you observed seems different from what is described here, e.g., which looks the same as you expected to get. Is this correct? Commented Feb 28, 2022 at 10:08
  • @sancho.sReinstateMonicaCellio It is similiar. If it is the best option I can get, it will do.
    – menteith
    Commented Mar 1, 2022 at 17:34
  • @menteith so are you saying that 60 is the only color that you are willing to use, but you want it to show up different? Basically all the answers below say there are 254 other colors, plenty of which will display different..... Or, on your system, does all 255 colors show up the way it shows in your picture? I would find that hard to believe because fg=60 shows up the same way on my screen as it does on yours, but the other colors, on mine, show as advertised.... see the chart in my answer and reference "60"... Let me know if I am misunderstanding?
    – WU-TANG
    Commented Mar 2, 2022 at 0:56

4 Answers 4

7

If you also have zsh-syntax-highlighting enabled, there's a known conflict with older versions of zsh-autosuggestions. The GitHub issue reports versions:

zsh-autosuggestions: v0.6.4
zsh-syntax-highlighting: 0.8.0-alpha2-dev

The workaround is:

[...] was able to fix the issue by updating both autosuggestions and syntax-highlighting to their latest versions from GitHub [...]

To clone,

git clone https://github.com/zsh-users/zsh-syntax-highlighting ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Alternately, you could git fetch then git pull, assuming no merge conflicts.

1
  • 1
    Thanks a million! Finally, this solutions works as expected!
    – menteith
    Commented Aug 1, 2022 at 13:27
2

Refer to the official documentation available on GitHub:

Set ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE to configure the style that the suggestion is shown with. The default is fg=8, which will set the foreground color to color 8 from the 256-color palette. If your terminal only supports 8 colors, you will need to use a number between 0 and 7.

Background color can also be set, and the suggestion can be styled bold, underlined, or standout. For example, this would show suggestions with bold, underlined, pink text on a cyan background:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff,bg=cyan,bold,underline"

For more info, read the Character Highlighting section of the zsh manual: man zshzle or online.

Note: Some iTerm2 users have reported not being able to see the suggestions. If this affects you, the problem is likely caused by incorrect color settings. In order to correct this, go into iTerm2's setting, navigate to profile > colors and make sure that the colors for Basic Colors > Background and ANSI Colors > Bright Black are different.

So, you can change the colour of the suggestions and make them bold (maybe even underlined).

Modify the ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE to:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#d787ff,bold'

It'll make it appear much brighter than before.

You might want to change it to some other colour, for example, Cyan:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#00ffff,bold'

You might like underlining the suggestion:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=#00ffff,bold,underline'

For the colour chat refer to the colour palette.

1
  • 1
    Do you think this answer adds to what the OP tried (other than explaining in more detail that same configuration)? Why would this produce a result essentially different from what the OP reported, in the sense of solving his/her problem? Commented Feb 28, 2022 at 10:06
-1

You can use:

# Change <your color> to a valid color
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=<your color>"
# For example, to make the text red:
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff0000"

The result will be like below, depending on the config you actually used: ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff0000"

You can append that line of setting to .zshrc.

EDIT: It is also possible to do almost any formatting on the suggested text. Here are some examples. ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff0000,bg=#00ff00,underline" ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff0000,bg=#00ff00,underline,standout,bold"

For a full list of formatting syntax, see it's official documentation. Hope you enjoy the reformatted texts and have a good day!

-2

I always use this color for contrast in terminals: (in my .zshrc file, I'd add)

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#00FF00,bold"

You're getting the color that you selected... 60 is a light magenta-ish color. I cut and pasted the script from here into my terminal and it output the color chart on that page to my terminal... displaying your "60" selection...

If I wanted to use those kind of codes to set my color preference, I'd do something like:

ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=46,bold"

...and get a similar result to the hex/rgb code in my 1st example above.

(in other words, there's nothing wrong, you're just picking a color you don't want.... pick another color, the chart(s) in the link above should help)

echotc Co will tell you how many colors your terminal supports, but I doubt you're going to need to verify that because you are getting the correct color for "60", so it is most likely 256.

Edit: I didn't realize there were so many charts and scripts on that page in the link. I just used the accepted answer from Tom Hale...

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .