jeff-hykin / better-shell-syntax

💾 📦 ♻️ An improvement to the shell syntax for VS Code
MIT License
52 stars 4 forks source link

Incorrect syntax highlighting of shell aliases #87

Open PavelSafronov opened 6 months ago

PavelSafronov commented 6 months ago

The code with a problem is:

alias ll='ls -alF'
alias ..='cd ..'

It looks like:

Screenshot 2024-05-07 at 3 45 52 PM

It should look like:

The two lines should have the same highlighting: alias should blue in both cases.

shtev21 commented 1 month ago

From what I can gather, it occurs when the alias has a period (as well as a few other characters).

All aliases that contain a . will have incorrect highlighting for the remainder of that alias' scope only and the problem doesn't 'bleed' to other aliases.

Examples

Syntax highlighting fails for l. alias but resumes for the following `rm alias:

image

Syntax highlighting fails for cd.. but NOT cd-

image

Is it the responsibility of a syntax highlighter to adhere to the specifications of a language even when that allows for valid code that has unexpected functionality?

Regarding valid aliases, the Bash man pages say:

Aliases 🔗

The characters /, $, `, and = and any of the shell metacharacters or quoting characters listed above may not appear in an alias name.

Metacharacter 🔗

A character that, when unquoted, separates words. A metacharacter is a space, tab, newline, or one of the following characters: ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ‘<’, or ‘>’.

Which seems to allow foo. as an acceptable alias, which seems reasonable. However it also allows bar[ which in my testing, causes the alias not to function as expected.