zsh-syntax-highlighting
zsh-syntax-highlighting copied to clipboard
Syntax highlighting seemingly not expanding variable substitutions in aliases
I override vi, vim, and nvim with a local version (if available).
The following is the relevant segments from .zshrc:
export VARERR='Error: Variable is not set.'
export EDITOR="/opt/nvim/bin/nvim"
if [ -x "${EDITOR:-}" ]; then
alias nvim="\${EDITOR:?\${VARERR}}"
alias vim="\${EDITOR:?\${VARERR}}"
alias vi="\${EDITOR:?\${VARERR}}"
fi
If the local nvim exists, the alias table is set as so:
» whence -va nvim vim vi
nvim is an alias for ${EDITOR:?${VARERR}}
nvim is /usr/bin/nvim
vim is an alias for ${EDITOR:?${VARERR}}
vim is /usr/bin/vim
vi is an alias for ${EDITOR:?${VARERR}}
vi is /usr/bin/vi
This causes zsh-syntax-highlighting to color vi in red, erroneously.
If the alias is more "conventional", then it works as expected, coloring vi in green:
I apologize in advance if this is not expected to work, or if it has already been reported.
I did a cursory search but did not see a similar issue.
This is morally the same as #771. z-sy-h will look though a small subset of parameter substitutions and doesn't at present distinguish between a known syntax error and parameter expansions it doesn't know how to look through safely.
I think an acceptable way to handle this (at least to me) would be to color aliases that exist, but are not simply parsable as yellow instead of red.
This seems an acceptable compromise, as it wouldn't make me do a double-take, thinking there is an error when there is not, and would be much easier to implement than complete substitution and expansion logic.
Yeah, that's our thinking too, as mentioned on the referenced issues. Interested in writing a patch for this? Some cases of variable expansion at command position are already handled; all that's needed is to have unhandled cases set some new style.
I might be able to write a decent patch... I'll give it a shot once I'm in front of a "real" computer, which should be sometime next week, unless someone else gets to it first.
Thanks, @johnsonjh. If you have questions about the approach or the details, do ask. And don't forget docs and tests :-)