213 points · by rainworld · 6y ago · 47 comments
Good point. Exit codes can be difficult. A non-zero error value may not be an error; it could indicate a type of success or be a warning or a result of a calculation or any number of things depending on the application.
It’s some of the most cursed code I’ve ever worked with.
(God bless anyone who ever used this program and got a set fault or sigint or sighup and therefore a bizarre result.)
Then, I read the part about each digit of the decimal representation.
Now I may need to lie down for a spell.
What is the decimal range of values used?
Personally, I think Result types from Rust/Haskell/Swift make a lot of sense -- a program either succeeds with some output, or fails with an explanation of why. By default, pipes stop piping if one command fails.
Usually, this is what happens. Usually, the error-signalling return is accompanied by a message (posted to stderr).
> By default, pipes stop piping if one command fails
set -o pipefailAnd there is in PowerShell - you can return arbitrary complex object.
As a Unix person my impression of PowerShell is that it’s more robust for scripting than the Unix shells, but that the Unix shells are more suitable for interactive use. And for anything of sufficient complexity and/or size I’d personally reach for either Python or I’d write a program in Rust.
I guess in the end it comes down to personal preference and what you are familiar with.
Incidentally, when I started at the university, when I was still using Windows, and PowerShell had recently come out I actually started with PowerShell and was getting comfortable with it. But we learned about Linux at the university and a friend I made at the university was showing me Linux stuff, and I started using Linux and FreeBSD instead of Windows. If it wasn’t for that then I’d probably have been a PowerShell person today.
Correct me if I'm wrong, but aren't exit codes an OS-level thing? That would be one hell of a redesign!
Not that I wouldn't absolutely love to have rich/structured return values, but that's already hard to do in a single-language system - even ignoring backwards compatibility, doing this in a traditional OS would require a level of cooperation I don't think the industry is capable of.
ls -fr | select (f: now() - f.mtime < days(1))
ls pipes File objects to the select, and that's a Python function inside the parens.Scripting is done in Python, using marcel's shell commands as functions, by importing the module marcel.api. So the examle above in Python would be:
from marcel.api import *
for file in (ls(file=True, recursive=True) |
select(lambda f: now() - f.mtime < days(1))):
print(file)
So it's the same shell command (ls ... | select ...), but expressed as Python functions, and the result is an iterator so that the command output can be used inside a for loop.For more info: https://www.marceltheshell.org, https://github.com/geophile/marcel.
I like bash for simple commands, but hate the requirement to learn so many sublanguages for more sophisticated usage, (as in sed, awk, find, and others). I like Python for scripting, but the integration of shell commands is really not very good. I built marcel to fix both of these problems.
I'd like to build the same but using the JVM/groovy as the runtime/scripting language.
How is Nushell able to use threads? For example how are subshells implemented?
Would definitely like to hear from the authors of Nushell on how their language choice has held up over the course of the project.
1: https://golang.org/src/syscall/exec_unix.go?s=7064:7143#L19
But $it is still useful in the absence of 'each'.
For instance:
dirname is a useful tool but you can't pipe to it (at least not the GNU version), it expects a string parameter. We can still easily plug it into nushell pipelines though, thanks to $it, which is this case is basically turning stdin into a string.
Since dirname won't let us do
which nu | get path | dirname
we can instead do which nu | get path | dirname $it
If I wanted to do this in bash, I'd have to go through some annoying (but common) machinations in order to convert stdin into a text string to pass to dirname.The default viewer, which sort of runs at the end of every pipeline is called `autoview`.
Now.. autoview should be calling textview in the cases where the pipeline detects a large text value. It is possible that you're not exactly running a pipeline.
For instance: If you run:
cat big.log
it is not running a pipeline, just an external command.If you run:
open big.log
you're invoking nushell's mechanism for creating a pipeline sourced by the contents of big.log. You should also notice that textview is invoked, because there should be a pager.
Alternatively, you can choose to create a pipeline by pipe-ing the output of cat big.log into something.
If you pipe it to textview you should see the same result: cat big.log | textview
Hope that helps!As far as i can tell no way to define any function/commands(you have to write plugins in another language, make an executable??). It supports pipeline, has a large amounts of built-in operators/commands(probably enough to be usable as a shell) and built-in parsers for a few formats(how does one write support for another data format?). Maybe in future it will address these questions.
> Looking at Nu today, you can see some common parts of languages like `if` or `open`, but it doesn’t yet feel like there’s enough syntax to build up full programs. You can’t define your own commands, your own variables, and you can’t build out a project across multiple files. We’re working to address all of these limitations so that Nu can function not only for one-liners, but also for much more.
There are bulti-in methods like `parse` and `split`, `format` which can provide awk-like behavior. However, there are many other built-in methods which operate on tables, floats, vectors and integers.
I actually have a ticket in to make some of the parsing behavior a bit more "awk like" (https://github.com/nushell/nushell/issues/2375)