You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On go we use ... do indicate all sub-folders: go test -coverprofile=coverage.out -cover ./pkg/...
Cases like this shouldn't be expanded.
How to reproduce
On any go project you can try to run the tests by doing:
$ go test -coverprofile=coverage.out -cover ./pkg/...
no Go files in /Users/herlon/go/src/github.com/herlon214
Because ... is expanded it tries to run the tests in the wrong folder.
Expected behavior
$ go test -coverprofile=coverage.out -cover ./pkg/...
ok github.com/herlon214/sonarqube-pr-issues/pkg/scm 0.179s coverage: 87.7% of statements
ok github.com/herlon214/sonarqube-pr-issues/pkg/sonarqube 0.234s coverage: 81.1% of statements
I'm thinking we should have a way to disable path expansions. There are use cases where you just want to pass the raw string. For example, recently, I wanted to remove a directory named ~ I accidentally created. It might be quite hard, though, since path expansions happen all over the place.
I am running into a similar issue with tar. It will change the path the file is packaged into depending on if the path is relative or absolute. Since . is expanded to the full absolute path by nushell, I can't make the packaged files top-level.
@kubouch@leroycep at least the . and .. thing has been implemented in #5180; however, this does not change the behavior of .... If we wanted to, we could only expand ...+ at the beginning of paths, but that would result in Weird Behavior imo.
Is there a way to explicitly suppress path expansion? './...' and "./..." behave the same way as ./... for me, so quotes don't seem to suppress expansion.
It appears that Nu no longer expands ... in most cases. (I'm having a hard time understanding the exact rules; it seems that ls might be a special case, even though type ls states that it's using my standard GNU version, not a built-in.)
It appears that Nu no longer expands ... in most cases. (I'm having a hard time understanding the exact rules; it seems that ls might be a special case, even though type ls states that it's using my standard GNU version, not a built-in.)
do you have an example where ... does not expand and it should? 😋
@amtoine I meant that I don't know what the rules should be, since my only context for the behavior is this thread and my own experimentation. Searching for "..." in the Book doesn't seem to yield any useful results, and it's not mentioned in help path expand, so I don't even know how to find documentation about what the expected expansion behavior is.
What I've observed is that using the full path of my ls binary has different behavior than just using ls as the command name:
~/sandbox/git/sub> type ls 06/29/2023 05:37:30 PM
ls is /opt/homebrew/opt/coreutils/libexec/gnubin/ls
~/sandbox/git/sub> ls ... 06/29/2023 05:37:36 PM
╭───┬──────────────┬──────┬───────┬──────────────╮
│ # │ name │ type │ size │ modified │
├───┼──────────────┼──────┼───────┼──────────────┤
│ 0 │ ../../git │ dir │ 192 B │ a minute ago │
│ 1 │ ../../go │ dir │ 96 B │ 2 days ago │
│ 2 │ ../../pyquil │ dir │ 128 B │ 6 hours ago │
│ 3 │ ../../rust │ dir │ 128 B │ 2 weeks ago │
╰───┴──────────────┴──────┴───────┴──────────────╯
~/sandbox/git/sub> /opt/homebrew/opt/coreutils/libexec/gnubin/ls ... 06/29/2023 05:37:44 PM
ls: cannot access '...': No such file or directory
Coming from other shells, this seems surprising (since normally I'd expect that type would report exactly what a command will do, and if it's an external binary, replacing the command with the full binary path shouldn't change anything except what the binary receives as arg[0]). But "surprising" doesn't necessarily seem "wrong", since, again, I don't know what the intended behavior is.
@amtoine To be clear, when I said that Nu "no longer expands ... in most cases", I meant that this GitHub issue might be resolved. In particular, it seems that there is no longer any problem using standard Go commands in Nu.
there is a little confusion there 😉 type is an external command, probably some system command that gives the path of the binary linked to some command name, e.g. ls is /opt/homebrew/opt/coreutils/libexec/gnubin/ls
now ls is the builtin ls command in Nushell, which does not have anything to do with the one on your system 😮
so when you run /opt/homebrew/opt/coreutils/libexec/gnubin/ls, it's like running ^ls, i.e. the external command.
when you run ls, it's the builtin command 👍
Note
i bet you'll get something like the following 😏
To be clear, when I said that Nu "no longer expands ... in most cases", I meant that this GitHub issue might be resolved. In particular, it seems that there is no longer any problem using standard Go commands in Nu.
this is good new 🥳
have you been able to not reproduce the example of the OP then?
if so, we can close this and see if the bug reappears 😌
@amtoine Yes, as far as I can tell, this issue should be closed. (Which is great, because it was one of the blockers for me adopting Nushell!)
The rest of this comment is about type and why its behavior is confusing. I think it would be helpful (especially for Mac users) for Nu to alias type to whichby default.
I had forgotten that type isn't built in to nu... but apparently type itself "lies" about this:
~: type type 06/30/2023 12:33:15 PM
type is a shell builtin
~: which type 06/30/2023 12:33:18 PM
╭───┬──────┬───────────────┬──────────╮
│ # │ arg │ path │ built-in │
├───┼──────┼───────────────┼──────────┤
│ 0 │ type │ /usr/bin/type │ false │
╰───┴──────┴───────────────┴──────────╯
Note that in most shells, type is more accurate than which, because which only searches for external binaries:
!>typeechoecho is a shell builtin!> which echo
/opt/homebrew/opt/coreutils/libexec/gnubin/echo
...and, in most shells, type itself is a built-in whereas which is not:
!>typetypetype is a shell builtin!>type which
which is hashed (/usr/bin/which)
Having type implemented as an external binary seems to be an oddity that's specific to BSD. On my Mac, type -a type prints:
type is a shell builtintype is /usr/bin/type
...but this is not true of a Linux-based system running Bash:
!> docker run -it bash
bash-5.2# type -a typetype is a shell builtin
@amtoine Yes, as far as I can tell, this issue should be closed. (Which is great, because it was one of the blockers for me adopting Nushell!)
this is good news, let's close this then if we can't reproduce the issue 👍
The rest of this comment is about type and why its behavior is confusing. I think it would be helpful (especially for Mac users) for Nu to alias type to which by default.
@amtoine I emphasized "by default" very intentionally. Now that I know BSD (and only BSD!) has a type binary that invokes sh, it's not a problem for me. The problem is for people who don't know this, and, like me, expect type to give accurate information within the current shell.
i do not think it's Nushell's responsibility to make sure system-specific commands like type do what they "are supposed" to do in these other systems, it just sounds not tractable to me 😕
however, maybe the Thinking in Nu chapter of the book could benefit from having a section talking about that!
somethings that mentions the which command and explains that external / non built-in commands are not to be expected to integrate directly with Nushell because Nushell does not know about all of them 👍
would that be a good middle ground for our scenario here @BatmanAoD? 😇
I'll leave it up to you, and I'm certainly sympathetic to the point that working around non-standard behavior isn't really "Nushell's responsibility." I do want to clarify, though, that BSD's behavior isn't "wrong" per se, it's just...weird and surprising, especially to people like me who are more accustomed to Linux. (I've only recently started using a Mac for work.) In most OSes, if your shell has a built-in, then you can't use the built-in from outside the shell; you'd almost expect that to be part of the definition of a "built-in." But instead, BSD-derived platforms will invoke sh and call the built-in from there, without any indication to the user that this is what's happening. (To be clear, the issue is not that I expected a command from outside of Nu to be integrated in some deeper way with Nu; the issue is that I thought typewas a Nu built-in, because of the way type itself behaves.)
Since Mac OS is a pretty common operating system, my point here is really just that this confusion will potentially recur. On Linux and Windows there's not really a problem, because attempting to use type just returns the standard missing-command error message.
I realize that all of the built-ins "implemented as scripts" according to that BSD man page I linked are potentially confusing. But I think type is something of a special case just because it's such a useful tool when exploring a shell, and also because nu already has a built-in (which) that behaves the way type behaves in unix-y shells. Additionally, I think it's the one with the most potential for confusion, since it explicitly states that certain commands are built-ins...but they're built-in to sh, not nu. (The other really surprising command listed on that man page is unalias, for which I honestly can't think of a legitimate use case for the /usr/bin/unalias script; but as far as I can tell there are no "default" aliases in Mac OS, so in general, unalias <foo> will just print an error message.)
So, basically, I just think that aliasing type -> which could prevent a lot of confusion and generally make nu behave in an unsurprising way for people coming from other shells; and I also can't think of any similar cases where a system binary on a common operating system would cause this specific type of confusion, where the output of the command doesn't make it immediately obvious that the command isn't a built-in. (To be fair, though, the fact that the output wasn't formatted as a table should have been a giveaway.)
In any case, this is the last I'll say about it, and as I mentioned above, I do understand not making any change to address it, since it's essentially just a weird quirk of a certain operating system. I appreciate the suggestion of adding some text to "Thinking in Nu", but I'm not sure what would help, given that the problem is more about how type itself behaves. Maybe it could be added to a list of "footguns"?
[Side note: A potentially more robust, but also more complex, solution would be to have nu's command invocation logic prohibit directly invoking any of these posix shell built-ins as external scripts, without ^ or an explicit path. A list of these "prohibited" commands could be derived from scraping man builtin (perhaps while generating the default config file) or whenever a file under /usr/bin/ is invoked by examining the file contents (which are always the same four lines: the shebang, a FreeBSD public domain notice, and then a fancy builtin $0). ]
Activity
sophiajt commentedon Apr 14, 2022
I thought we changed it so
...only expanded at the front? hmmmMaybe we should use @strega-nil's idea and do that?
kubouch commentedon Apr 15, 2022
I'm thinking we should have a way to disable path expansions. There are use cases where you just want to pass the raw string. For example, recently, I wanted to remove a directory named
~I accidentally created. It might be quite hard, though, since path expansions happen all over the place.leroycep commentedon Apr 16, 2022
I am running into a similar issue with
tar. It will change the path the file is packaged into depending on if the path is relative or absolute. Since.is expanded to the full absolute path by nushell, I can't make the packaged files top-level.kubouch commentedon Apr 16, 2022
Should we just disable path expansion on externals altogether? 🤔 I'm wondering if it would break anything but you can always
path expandmanually.strega-nil commentedon Apr 16, 2022
@kubouch @leroycep at least the
.and..thing has been implemented in #5180; however, this does not change the behavior of.... If we wanted to, we could only expand...+at the beginning of paths, but that would result in Weird Behavior imo.BatmanAoD commentedon May 13, 2022
Is there a way to explicitly suppress path expansion?
'./...'and"./..."behave the same way as./...for me, so quotes don't seem to suppress expansion.kubouch commentedon May 14, 2022
@BatmanAoD No, but there should be. You can try
./...but I think it will expand as well.BatmanAoD commentedon May 16, 2022
😆 😭
eyepatchParrot commentedon Jun 7, 2022
I have a simpler example here:
My expectation is that there would be a way of quoting a string so that it isn't path expanded.
BatmanAoD commentedon Jun 29, 2023
It appears that Nu no longer expands
...in most cases. (I'm having a hard time understanding the exact rules; it seems thatlsmight be a special case, even thoughtype lsstates that it's using my standard GNU version, not a built-in.)amtoine commentedon Jun 29, 2023
@BatmanAoD
do you have an example where
...does not expand and it should? 😋BatmanAoD commentedon Jun 30, 2023
@amtoine I meant that I don't know what the rules should be, since my only context for the behavior is this thread and my own experimentation. Searching for
"..."in the Book doesn't seem to yield any useful results, and it's not mentioned inhelp path expand, so I don't even know how to find documentation about what the expected expansion behavior is.What I've observed is that using the full path of my
lsbinary has different behavior than just usinglsas the command name:Coming from other shells, this seems surprising (since normally I'd expect that
typewould report exactly what a command will do, and if it's an external binary, replacing the command with the full binary path shouldn't change anything except what the binary receives asarg[0]). But "surprising" doesn't necessarily seem "wrong", since, again, I don't know what the intended behavior is.BatmanAoD commentedon Jun 30, 2023
@amtoine To be clear, when I said that Nu "no longer expands
...in most cases", I meant that this GitHub issue might be resolved. In particular, it seems that there is no longer any problem using standard Go commands in Nu.amtoine commentedon Jun 30, 2023
@BatmanAoD
about the first part:
there is a little confusion there 😉
typeis an external command, probably some system command that gives the path of the binary linked to some command name, e.g.lsis/opt/homebrew/opt/coreutils/libexec/gnubin/lsnow
lsis the builtinlscommand in Nushell, which does not have anything to do with the one on your system 😮so when you run
/opt/homebrew/opt/coreutils/libexec/gnubin/ls, it's like running^ls, i.e. the external command.when you run
ls, it's the builtin command 👍this is good new 🥳
have you been able to not reproduce the example of the OP then?
if so, we can close this and see if the bug reappears 😌
BatmanAoD commentedon Jun 30, 2023
@amtoine Yes, as far as I can tell, this issue should be closed. (Which is great, because it was one of the blockers for me adopting Nushell!)
The rest of this comment is about
typeand why its behavior is confusing. I think it would be helpful (especially for Mac users) for Nu to aliastypetowhichby default.I had forgotten that
typeisn't built in tonu... but apparently type itself "lies" about this:Note that in most shells,
typeis more accurate thanwhich, becausewhichonly searches for external binaries:...and, in most shells,
typeitself is a built-in whereaswhichis not:Having
typeimplemented as an external binary seems to be an oddity that's specific to BSD. On my Mac,type -a typeprints:...but this is not true of a Linux-based system running Bash:
Looking at Mac's man page for builtins, it says:
...and, indeed,
typeis markedNo**... andcat /usr/bin/typeprints:amtoine commentedon Jul 1, 2023
this is good news, let's close this then if we can't reproduce the issue 👍
the quick fix here is to add
to your
config.nufile 😋BatmanAoD commentedon Jul 1, 2023
@amtoine I emphasized "by default" very intentionally. Now that I know BSD (and only BSD!) has a
typebinary that invokessh, it's not a problem for me. The problem is for people who don't know this, and, like me, expecttypeto give accurate information within the current shell.amtoine commentedon Jul 2, 2023
@BatmanAoD
i do not think it's Nushell's responsibility to make sure system-specific commands like
typedo what they "are supposed" to do in these other systems, it just sounds not tractable to me 😕however, maybe the Thinking in Nu chapter of the book could benefit from having a section talking about that!
somethings that mentions the
whichcommand and explains that external / non built-in commands are not to be expected to integrate directly with Nushell because Nushell does not know about all of them 👍would that be a good middle ground for our scenario here @BatmanAoD? 😇
BatmanAoD commentedon Jul 2, 2023
I'll leave it up to you, and I'm certainly sympathetic to the point that working around non-standard behavior isn't really "Nushell's responsibility." I do want to clarify, though, that BSD's behavior isn't "wrong" per se, it's just...weird and surprising, especially to people like me who are more accustomed to Linux. (I've only recently started using a Mac for work.) In most OSes, if your shell has a built-in, then you can't use the built-in from outside the shell; you'd almost expect that to be part of the definition of a "built-in." But instead, BSD-derived platforms will invoke
shand call the built-in from there, without any indication to the user that this is what's happening. (To be clear, the issue is not that I expected a command from outside of Nu to be integrated in some deeper way with Nu; the issue is that I thoughttypewas a Nu built-in, because of the waytypeitself behaves.)Since Mac OS is a pretty common operating system, my point here is really just that this confusion will potentially recur. On Linux and Windows there's not really a problem, because attempting to use
typejust returns the standard missing-command error message.I realize that all of the built-ins "implemented as scripts" according to that BSD man page I linked are potentially confusing. But I think
typeis something of a special case just because it's such a useful tool when exploring a shell, and also becausenualready has a built-in (which) that behaves the waytypebehaves in unix-y shells. Additionally, I think it's the one with the most potential for confusion, since it explicitly states that certain commands are built-ins...but they're built-in tosh, notnu. (The other really surprising command listed on that man page isunalias, for which I honestly can't think of a legitimate use case for the/usr/bin/unaliasscript; but as far as I can tell there are no "default" aliases in Mac OS, so in general,unalias <foo>will just print an error message.)So, basically, I just think that aliasing
type->whichcould prevent a lot of confusion and generally makenubehave in an unsurprising way for people coming from other shells; and I also can't think of any similar cases where a system binary on a common operating system would cause this specific type of confusion, where the output of the command doesn't make it immediately obvious that the command isn't a built-in. (To be fair, though, the fact that the output wasn't formatted as a table should have been a giveaway.)In any case, this is the last I'll say about it, and as I mentioned above, I do understand not making any change to address it, since it's essentially just a weird quirk of a certain operating system. I appreciate the suggestion of adding some text to "Thinking in Nu", but I'm not sure what would help, given that the problem is more about how
typeitself behaves. Maybe it could be added to a list of "footguns"?[Side note: A potentially more robust, but also more complex, solution would be to have
nu's command invocation logic prohibit directly invoking any of these posix shell built-ins as external scripts, without^or an explicit path. A list of these "prohibited" commands could be derived from scrapingman builtin(perhaps while generating the default config file) or whenever a file under/usr/bin/is invoked by examining the file contents (which are always the same four lines: the shebang, a FreeBSD public domain notice, and then a fancybuiltin $0). ]amtoine commentedon Jul 4, 2023
@BatmanAoD
thanks for the writeup, this is very clear and very sensible 👍
i'll talk about that in the next @nushell/core-team meeting, just to see what others think about that 😉
BatmanAoD commentedon Jul 4, 2023
@amtoine Thanks very much!