zsh-syntax-highlighting
zsh-syntax-highlighting copied to clipboard
With NO_UNSET, highlight unset parameter expansions as errors
It would be nice for —
set -u
unset foo
echo "$foo"
— to highlight the $foo as an error (= in red), since that line would fail to execute.
I worry about adding this because I suspect if we do, someone will some along asking why
unset foo; echo "$foo"
doesn't highlight that $foo in red.
Note also #239 which is the same thing but with $options[unset] at its default setting.
@phy1729 Is there an analogy we can use? E.g., touch foo; : foo and the second foo isn't underlined. This may be a hard sell though so I wonder whether we have a more convincing analogy.
Perhaps cc foo.c -o foo; ./foo, but both are false positives not false negatives. Although in all cases it is arguable z-sy-h shouldn't become a perfect zsh oracle and the highlighting behaves in an expected although technically incorrect way.
It's easy to convert between false positive and false negative, e.g., rm foo; make foo or foo=42; echo "$foo".
I think the expected behaviour should be to highlight according to the state before the line is executed. I could see us support some additional simple cases (like how master supports $foo and ${foo} but nothing more than that) if somebody wrote the code.
.. meant in a "patches welcome" sense.
The design needs to consider history modifiers $foo:h and subscripts $foo[42].
I'm not sure what I had in mind when I mentioned history modifiers.
Related: In master we now highlight unset parameters in command position as comments.
This should happen for both echo $foo (unquoted) and echo "$foo" (double-quoted).