zsh-autosuggestions
zsh-autosuggestions copied to clipboard
Disable completions when line contains a comment
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)
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?)
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.
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.