Language Injection

The language injection feature of your IDE lets you define that some content of your script is written in another language. BashSupport Pro comes with full support for language injections.

Control Injection

There are two ways to define which language is injected.

  1. Alt & EnterInject language or reference : This intention lets you define the injected language temporarily.
  2. # language= comments: Content of elements, which follow such a comment, is automatically highlighted with the given language. Commonly used languages are HTML, XML, Java, or JSON. Try file extensions like kt, if you don’t know which ID to use here.

Example

HTML injected into a double-quoted string
HTML injected into a double-quoted string
Editing an HTML fragment, which is injected into a Bash string
Editing an HTML fragment, which is injected into a Bash string

The editor window, which only displays the injected content, is called a fragment editor.

Language Injection Into Strings

1
2
3
4
5
6
# language=HTML
echo "<html><body>
    <h1>Report</h1>
    <p>My name is $USER, 
       and my \$HOME is $HOME.</p>
</body></html>"

Strings support escaping. Escaped characters are unescaped in the fragment editor, e.g. \$HOME is shown as $HOME.

Typing ", $, or ` will insert the escaped characters \", \$, or \`. This way you don’t need to care about Bash’s escaping rules when you’re working in the fragment editor.

Strings support embedded subshell commands and other substitutions. These sections of the string are displayed as read-only in the fragment editor. Otherwise it wouldn’t be possible to enter the equivalent of \$HOME=$HOME in the fragment editor.

Language Injection Into Raw Strings

1
2
3
4
5
6
# language=HTML
echo '<html><body>
    <h1>Report</h1>
    <p>My name is contained in $USER, 
       and my HOME is contained $HOME.</p>
</body></html>'

Content in raw strings is displayed as is. There’s no escaping, except for the single quote '. Single quotes can only be escaped within $''.

BashSupport Pro automatically changes '' into $'' when you enter the first single quote character in the fragment editor.

Injection Into Here Documents

1
2
3
4
5
6
7
8
# language=HTML
cat - << EOF
  <html><body>
    <h1>Report</h1>
    <p>My name is $USER,
       and my \$HOME is $HOME.</p>
  </body></html>
EOF

Here documents with plain, unquoted markers support subshell commands and other substitutions. BashSupport Pro displays these sections as read–only in the same way as for strings. Escaping is supported, too.

Here document with quoted markers, e.g. "EOF", don’t support substitutions. Therefore escape code handling is not needed in this context.

© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal