zsh-autosuggestions
zsh-autosuggestions copied to clipboard
Can I set `ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE` to show red text when `history` autosuggest strategy is used and blue text when `completion engine` is used?
I know that:
ZSH_AUTOSUGGEST_STRATEGY=(history completion)will first try to find a suggestion from thehistory, but, if it can't find a match, will find a suggestion from thecompletionengine.ZSH_AUTOSUGGEST_HIGHLIGHT_STYLEconfigures the style that a suggestion is shown with.
Question: Is there a way to show one font color (e.g. red) for suggestions from my history and another font color (e.g. blue) for suggestions from the completion engine?
There's not really a supported way to do this right now. I was thinking that you may be able to write custom strategy wrapper functions around the history and completion strategy functions and set ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE accordingly in those wrapper functions, but that only works without async mode enabled, because in async mode the suggestion fetching runs in a separate process so can't set the value of the highlight style variable for the original process.
_zsh_autosuggest_strategy_color_completion() {
_zsh_autosuggest_strategy_completion "$*"
typeset -g ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=red'
}
ZSH_AUTOSUGGEST_STRATEGY=(color_completion)
The way the async code works right now, the only thing communicated back to the main process is the actual suggestion. It doesn't send any info about what strategy generated the suggestion, so we'd need to figure that out first. This is the place where we get data back from the async process:
https://github.com/zsh-users/zsh-autosuggestions/blob/ae315ded4dba10685dbbafbfa2ff3c1aefeb490d/src/async.zsh#L64-L71
Maybe the async process could always send the name of the strategy that generated the suggestion as a separate line at the beginning.
We'd also need to modify the _zsh_autosuggest_fetch_suggestion function. Currently it only "returns" the suggestion (by setting the global suggestion parameter) but we'd need it to potentially set another global param to send the strategy back as well.
https://github.com/zsh-users/zsh-autosuggestions/blob/ae315ded4dba10685dbbafbfa2ff3c1aefeb490d/src/fetch.zsh#L9-L27
Wow thanks @ericfreese for the detailed reply! Interesting. I'm not too familiar with zsh and shell scripting in general so I don't know if I'd be able to make the changes myself. Do you think this is something that people would want? (I do :) )
Would it be a change that a contributor to the repo would want to make?