Giter Site home page Giter Site logo

Comments (8)

kubouch avatar kubouch commented on June 13, 2024

The output of a string interpolation is a string, so that IMO works as intended.

Adding a bareword interpolation could work, I think, but the difference between

ls $`($nu.default-config-dir)/*.nu`

vs.

ls $"($nu.default-config-dir)/*.nu"

might not be obvious. It might seem confusing that one expands and the other doesn't.

from nushell.

NotTheDr01ds avatar NotTheDr01ds commented on June 13, 2024

It might seem confusing that one expands and the other doesn't.

Given that a backtick-quoted string is supposed to represent a path, it will hopefully be obvious that the behavior should be different. But also, to be fair, the backtick quoted behavior is already different (and should be):

  • ls `*` : Returns a list of all files in the current directory matching the glob pattern *
  • ls '*': Returns a file or directory literally named *

The feature request is just to add string-interpolation so that we can do it dynamically once again (without into glob).

from nushell.

NotTheDr01ds avatar NotTheDr01ds commented on June 13, 2024

Adding a bareword interpolation could work

Hmm - What would that look like?

from nushell.

kubouch avatar kubouch commented on June 13, 2024

Backticks define barewords, not strings. The intention of backticks is to have a similar behavior as if you typed the words without anything (this it not 100% consistent everywhere but that's the intention). So

$`...`

would be a bareword interpolation, not a string interpolation.

from nushell.

WindSoilder avatar WindSoilder commented on June 13, 2024

Follows the same rules to backtick-quoted word, I think we can't assign bareword interpolation to a variable.

from nushell.

kubouch avatar kubouch commented on June 13, 2024

Yeah. In theory, the following should be identical:

let x = git status
let x = `git status`

They both should run the command and save the result to x (in reality, the backticks seem to be broken in this case). On the other hand, let x = 'git status' will save the string to x.

from nushell.

NotTheDr01ds avatar NotTheDr01ds commented on June 13, 2024

Ok, so somewhere in the past I had read that backticks indicated a path, but that's not really the case.

I probably need to close this as an X/Y problem, but is there any way we can get string interpolation to work with globs short of into glob? It's something we used to have - it was nice and clean. Now we've lost it.

Personally, I'd much rather have to escape * with str escape-glob when I want a literal * in a string. I admit that I could be missing a 'bigger picture' here, but personally it seems to me that the wrong decision was made here. If an asterisk is found in a string, and that string is treated as a path, isn't it far more likely that the user intended it to be a glob than a literal character? Same with using ~ and other "path-like" characters.

When I started having to modify my scripts to add into glob, it seemed like a huge step backwards in usability. I was thinking perhaps backticks would be a suitable workaround, but that doesn't seem to be the case either.

from nushell.

kubouch avatar kubouch commented on June 13, 2024

We made it stricter to avoid unwanted glob expansion. Now, the rules are more consistent and predictable, you can look up the PR that added into glob and related issues for more context, it solved numerous problems. If we auto-expand by default and require std escape-glob, we'd have users complaining about that. Can't have both.

from nushell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.