Skip to content

Behaviour of comments in shell usage #8137

Closed

Description

@MangoIV

Question

Hi, I'm using nix and hence I write commands like this very often:
nix <command> <some-flake>#<output>. The issue here is the # which gets interpreted as a comment in nu.
Is it possible to turn off this behavior or somehow make it such that the comment syntax is indeed \s# like in other shells?
putting everything in " is a huge PITA.

Thanks in advance!

Additional context and details

nu version is 0.71.0

Activity

  1. added
    deprecated:question
    on Feb 20, 2023
  2. sholderbach commented on Feb 20, 2023

    @sholderbach
    Member

    Duplicate of #6335

    Requiring the space before end of line comments in the lexer would certainly be a breaking change for some people that have put (doc)comments directly after the documented item.
    Personally having the space is pleasant style to me, so I wouldn't oppose making that change.
    I don't know if we have any technical hurdles to making that change.
    The only nushell design goal that might be a bit at odds with it is our desire to be less sensitive to whitespace mistakes as bash (looking at you test [[ -w tf ]] syntax) and everything that looks ok whitespace wise should also be valid nu code.

  3. MangoIV commented on Feb 20, 2023

    @MangoIV
    ContributorAuthor

    Mmmh, i kinda expected that this was going to be the answer. Consider that this is quite limiting to nix users… idk how the plugin system works, yet, but is it perhaps possible to add one that allows # to be used like this?

  4. sholderbach commented on Feb 20, 2023

    @sholderbach
    Member

    Plugins can only contribute commands at the moment and do not positively interact with the parser logic so that is a no.

    I think the answer to this problem is to change the lexer/parser and see what the blast radius of the change would be.

  5. MangoIV commented on Feb 20, 2023

    @MangoIV
    ContributorAuthor

    Perhaps it can be added as a setting? Are there already settings that somehow interact with the parser?

  6. sholderbach commented on Feb 20, 2023

    @sholderbach
    Member

    We are pre-1.0, so I would say we make this change, but we shouldn't add a setting that mucks with how the parser behaves. Code snippets should generally work independent of your config. The config should be there to improve your interactive experience or deal with specific behavior of your system.

  7. MangoIV commented on Feb 20, 2023

    @MangoIV
    ContributorAuthor

    mmmh, so the change seems to be rather simple (deleting one line). It now works as I'd expect it to.

  8. MangoIV commented on Feb 20, 2023

    @MangoIV
    ContributorAuthor

    it seems to me as this is behavior is not tested for as all tests still pass after adding this change.

  9. MangoIV commented on Feb 20, 2023

    @MangoIV
    ContributorAuthor

    This is the commit that fixes the behaviour: 4d5317d

  10. added a commit that references this issue on Feb 22, 2023
    d0e0701
  11. added this to the v0.77.0 milestone on Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    deprecated:question

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions