Skip to content

Bash ANSI-C quoting highlighting #2436

Closed

Description

@smhmd

Information

  • Language: Bash
  • Plugins: none

Description
ANSI-C quoting in bash

Code snippet

The code being highlighted incorrectly.
echo $'module.exports = {\n  extends: [\n    // add more generic rulesets here, such as:\n    // 'eslint:recommended',\n    "plugin:vue/vue3-recommended",\n    "prettier",\n    "prettier/vue",\n  ],\n  rules: {\n    // override/add rules settings here, such as:\n    // 'vue/no-unused-vars': 'error'\n  },\n};' > .eslintrc.js

Reference: https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html

How is this supposed to look (zsh-fast-syntax-highlighting):
image
It seems that \n trips the highlighting.

Activity

  1. RunDevelopment commented on Jun 27, 2020

    @RunDevelopment
    Member

    The \ns aren't a problem, but the single quotes around 'eslint:recommended' are. I've also never seen $'something' before. Edit. Should have read the doc. First point stands tho.

  2. RunDevelopment commented on Mar 7, 2021

    @RunDevelopment
    Member

    Prism's highlighting is (mostly) correct.

    image

    In your example, you echo multiple strings that are concatenated and not one long string. As per spec:

    Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

    Here is the output of the echo command on my machine:

    micha@DESKTOP-DCVE9I0:/mnt/c/Users/micha$ echo $'module.exports = {\n  extends: [\n    // add more generic rulesets here, such as:\n    // 'eslint:recommended',\n    "plugin:vue/vue3-recommended",\n    "prettier",\n    "prettier/vue",\n  ],\n  rules: {\n    // override/add rules settings here, such as:\n    // 'vue/no-unused-vars': 'error'\n  },\n};'
    echo $'module.exports = {\n  extends: [\n    // add more generic rulesets here, such as:\n    // 'eslint:recommended',\n    "plugin:vue/vue3-recommended",\n    "prettier",\n    "prettier/vue",\n  ],\n  rules: {\n    // override/add rules settings here, such as:\n    // 'vue/no-unused-vars': 'error'\n  },\n};'
    module.exports = {
      extends: [
        // add more generic rulesets here, such as:
        // eslint:recommended,\n    "plugin:vue/vue3-recommended",\n    "prettier",\n    "prettier/vue",\n  ],\n  rules: {\n    // override/add rules settings here, such as:\n    // vue/no-unused-vars: error\n  },\n};

    That being said, I'll add support for ANSI-C Quoting.

  3. smhmd commented on Mar 7, 2021

    @smhmd
    Author

    I see. So, ANSI-C quotes behave differently in bash and zsh.
    image

  4. RunDevelopment commented on Mar 7, 2021

    @RunDevelopment
    Member

    That's interesting. zsh docs says this:

    A string enclosed between ‘$’’ and ‘’’ is processed the same way as the string arguments of the print builtin, and the resulting string is considered to be entirely quoted. A literal ‘’’ character can be included in the string by using the ‘\’’ escape.

    Luckily, the doc for print doesn't mention how string arguments are processed... At least, I couldn't find it. If I had to guess, then zsh requires a space (or the end of the command/line) after the second ' for it to be the closing quote.

    Anyway, the zsh behavior is incompatible with bash and won't be supported in the bash language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions