Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Shell Script (Bash) #434

Closed
8 tasks
wbond opened this issue May 26, 2016 · 6 comments · Fixed by #1057
Closed
8 tasks

Rewrite Shell Script (Bash) #434

wbond opened this issue May 26, 2016 · 6 comments · Fixed by #1057

Comments

@wbond
Copy link
Member

wbond commented May 26, 2016

Probably one of the buggiest syntaxes right now is Shell Script (Bash). Some current issues/PRs:

Work was done on improving the current state of things by @jfcherng with https://packagecontrol.io/packages/ShellScriptImproved. He indicated that he didn't think that was maintainable long term, hence this issue.

Issues that need to be addressed with the rewrite:

  • Update regular expressions to only use new engine
  • Consume identifiers including - so partial commands/functions aren't highlighted
  • Create variations for TCSH and ZSH (http://hyperpolyglot.org/unix-shells)
  • Fix first line detection
  • Fix detection of function definitions
  • Detect command/operator names and don't highlight when used as params (e.g. dd if)
  • Handle $(), $(()) and ```` expansions
  • Heredocs

There are surely many more.

@michaelblyons
Copy link
Collaborator

Wishlist:

  • $(()) can include other expressions.

     foo=$(($(cat bar.txt | wc -l) + 5))
  • Escape sequences within strings recognize the "color" patterns and don't just capture the \e.

     echo -e "\e[31;44mRed on Blue\e[0m"

@jfcherng
Copy link
Collaborator

jfcherng commented May 26, 2016

Here's one that I do not fix.

empty=$((echo hello) > output.txt)

It looks like that it executes just like

empty=$(echo hello > output.txt)

so may be not parsed as $((.... But I am not sure.

@MattDMo
Copy link
Contributor

MattDMo commented May 30, 2016

It would be great if the new syntax had a separate scope for ALLCAPS_CONSTANTS.

[[:upper:]][[:upper:][:digit:]_]*

should do it IIRC.

Also, don't dump everything into keyword.other.shell, it's rather pointless. It would also be kind of cool if you could match unquoted strings containing / as paths, but that may have too many exceptions to be useful.

@jrappen
Copy link
Contributor

jrappen commented Aug 13, 2016

looking at #46 @jfcherng linked this test file by @okdana

@jfcherng
Copy link
Collaborator

There is a syntax test file that has been used for ShellScriptImproved. Feel free to re-use it if it helps.

@cjwelborn
Copy link

I thought I was going crazy watching ShellScript not highlight my function definitions (function foo { ...). I'm very thankful for ShellScriptImproved and hope to see this Issue get resolved. Thanks everyone 😄.

rwols added a commit to rwols/Packages that referenced this issue Jun 26, 2017
Issue links
-----------
Intends to close sublimehq#434
Fixes sublimehq#626
Fixes sublimehq#190
Fixes sublimehq#46

Goodies
-------

* Proper context sensitive command invocations
* Variable expansion as from ShellScriptImproved
* Backtick handling as from ShellScriptImproved
* No with_prototype contexts
* Generic options handling
* Builtin-commands know their valid options
* Renamed Shell-Unix-Generic to bash, as it's really just bash (and dash)

About 1300 syntax tests, tested out in the wild with various bash scripts.

Deficiencies
------------

The heredocs handling is still not perfect, but it gets the job done if you
don't have a function definition, inline if-block or compound command on
the same line as the start of the heredoc token.

* It's easy to bring back the embedded language highlighting for particular
  heredoc tokens, but this is omitted for now.
* It's easy to embed the regex language for regex matching in if-blocks at
  this point.

Acknowledgements
----------------

* @jfcherng for starting ShellScriptImproved and the huge amount of syntax
  tests,
* @okdana for creating syntax tests,
* @FichteFoll for pointing me to the Ruby syntax for heredoc handling,
* @KingKeith, @wbond for their suggestions about scope names.
rwols added a commit to rwols/Packages that referenced this issue Jun 26, 2017
Issue links
-----------
Intends to close sublimehq#434
Fixes sublimehq#626
Fixes sublimehq#190
Fixes sublimehq#46

Goodies
-------

* Proper context sensitive command invocations
* Variable expansion as from ShellScriptImproved
* Backtick handling as from ShellScriptImproved
* No with_prototype contexts
* Generic options handling
* Builtin-commands know their valid options
* Renamed Shell-Unix-Generic to bash, as it's really just bash (and dash)

About 1300 syntax tests, tested out in the wild with various bash scripts.

Deficiencies
------------

The heredocs handling is still not perfect, but it gets the job done if you
don't have a function definition, inline if-block or compound command on
the same line as the start of the heredoc token.

* It's easy to bring back the embedded language highlighting for particular
  heredoc tokens, but this is omitted for now.
* It's easy to embed the regex language for regex matching in if-blocks at
  this point.

Acknowledgements
----------------

* @jfcherng for starting ShellScriptImproved and the huge amount of syntax
  tests,
* @okdana for creating syntax tests,
* @FichteFoll for pointing me to the Ruby syntax for heredoc handling,
* @keith-hall, @wbond for their suggestions about scope names.
rwols added a commit to rwols/Packages that referenced this issue Jun 26, 2017
Issue links
-----------
Intends to close sublimehq#434
Fixes sublimehq#626
Fixes sublimehq#190
Fixes sublimehq#46

Goodies
-------

* Proper context sensitive command invocations
* Variable expansion as from ShellScriptImproved
* Backtick handling as from ShellScriptImproved
* No with_prototype contexts
* Generic options handling
* Builtin-commands know their valid options
* Renamed Shell-Unix-Generic to bash, as it's really just bash (and dash)

About 1300 syntax tests, tested out in the wild with various bash scripts.

Deficiencies
------------

The heredocs handling is still not perfect, but it gets the job done if you
don't have a function definition, inline if-block or compound command on
the same line as the start of the heredoc token.

* It's easy to bring back the embedded language highlighting for particular
  heredoc tokens, but this is omitted for now.
* It's easy to embed the regex language for regex matching in if-blocks at
  this point.

Acknowledgements
----------------

* @jfcherng for starting ShellScriptImproved and the huge amount of syntax
  tests,
* @okdana for creating syntax tests,
* @FichteFoll for pointing me to the Ruby syntax for heredoc handling,
* @keith-hall, @wbond for their suggestions about scope names.
deathaxe pushed a commit to deathaxe/sublime-packages that referenced this issue Jun 9, 2019
Issue links
-----------
Intends to close sublimehq#434
Fixes sublimehq#626
Fixes sublimehq#190
Fixes sublimehq#46

Goodies
-------

* Proper context sensitive command invocations
* Variable expansion as from ShellScriptImproved
* Backtick handling as from ShellScriptImproved
* No with_prototype contexts
* Generic options handling
* Builtin-commands know their valid options
* Renamed Shell-Unix-Generic to bash, as it's really just bash (and dash)

About 1300 syntax tests, tested out in the wild with various bash scripts.

Deficiencies
------------

The heredocs handling is still not perfect, but it gets the job done if you
don't have a function definition, inline if-block or compound command on
the same line as the start of the heredoc token.

* It's easy to bring back the embedded language highlighting for particular
  heredoc tokens, but this is omitted for now.
* It's easy to embed the regex language for regex matching in if-blocks at
  this point.

Acknowledgements
----------------

* @jfcherng for starting ShellScriptImproved and the huge amount of syntax
  tests,
* @okdana for creating syntax tests,
* @FichteFoll for pointing me to the Ruby syntax for heredoc handling,
* @keith-hall, @wbond for their suggestions about scope names.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants