zsh-syntax-highlighting icon indicating copy to clipboard operation
zsh-syntax-highlighting copied to clipboard

With NO_UNSET, highlight unset parameter expansions as errors

Open danielshahaf opened this issue 8 years ago • 8 comments

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.

danielshahaf avatar Nov 02 '17 17:11 danielshahaf

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.

phy1729 avatar Nov 16 '17 05:11 phy1729

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.

danielshahaf avatar Nov 16 '17 14:11 danielshahaf

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.

phy1729 avatar Nov 19 '17 04:11 phy1729

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.

danielshahaf avatar Nov 20 '17 01:11 danielshahaf

.. meant in a "patches welcome" sense.

danielshahaf avatar Nov 20 '17 01:11 danielshahaf

The design needs to consider history modifiers $foo:h and subscripts $foo[42].

danielshahaf avatar Jan 20 '18 15:01 danielshahaf

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.

danielshahaf avatar May 04 '20 23:05 danielshahaf

This should happen for both echo $foo (unquoted) and echo "$foo" (double-quoted).

danielshahaf avatar May 26 '20 18:05 danielshahaf