zsh-autosuggestions icon indicating copy to clipboard operation
zsh-autosuggestions copied to clipboard

Disable completions when line contains a comment

Open bretello opened this issue 1 year ago • 1 comments

Problem

When using ZSH_AUTOSUGGEST_STRATEGY=(completion), starting a comment inline sometime results in extra completions being shown after the start of the comment (# )

In the following example, -e is proposed as autosuggestion after the comment (completion for cat)

image

Solution

A potential approach could be disabling completions whenever a comment is started. I've experimented with the following:

export ZSH_AUTOSUGGEST_COMPLETION_IGNORE='* \#*'

which works in basic scenarios, but I'm sure it would break down in some cases (e.g. a string containing <space>#, multi-line statements?)

bretello avatar Dec 20 '23 20:12 bretello

I'm currently using @bretello's workaround to disable auto-suggestions within comments, but it's not ideal. My zshrc contains the following lines.

ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_COMPLETION_IGNORE='*\#*'
ZSH_AUTOSUGGEST_HISTORY_IGNORE='*\#*'

But now, if there is a # character in the command line that does not begin a comment, then I will no longer get suggestions.

image image

Maybe this could be solved for # characters contained within strings using a sufficiently fancy glob pattern, but there are other cases too (e.g. arr=(1 2 3); echo "${#arr[@]}" && ...), so I think another solution might be necessary.

pwnalone avatar Feb 15 '24 05:02 pwnalone