6 ms·
I think nushell makes a pretty good case against itself. Take ls: like the article says gnu ls has tons of options to configure how its output is displayed. Bu
by EdiX 3y ago
I think nushell makes a pretty good case against itself.
Take ls: like the article says gnu ls has tons of options to configure how its output is displayed. But that's because ls is a user interface for displaying lists of files. I'm not sure how the proponents of all these new shell keep missing this point. If you just want a list of files in a POSIX shell you use a glob expression.
But whatever, nushell has its own builtin ls that is for getting lists of files. And then you pipe it into other commands to configure the output. Great. Can I get the output to be like 'ls -C'? Nope. Can I turn off colors? No. Can I add the indicator character like 'ls -F'? Not a chance.
Well, at least I don't have to pass '-l' just to see the file mode... actually I do, otherwise it would be too slow.
Many of the options that clutter gnu ls are generic options that apply to all tables, and it would be nice to abstract them. But many aren't, many are specific to what ls is doing and it's hard to me to see how this all could be generalized in a way that applies both to ls and to grep.
For now nushell sidesteps the problem by not having its own reimplementation of grep, unlike ls if you type grep you get real grep and you can't pipe the output into anything meaningful.
The best I could do to replicate grep inside nushell was this:
cat haystack | split row -r '\n' | enumerate | where item =~ needle
asides from the shocking verbosity, I can't see any way to replicate the --color option of grep, or -A and -B.
The cop-out solution to this is to have builtins return objects (as in OOP objects, with methods), but then everything needs to be written in the same language.
- ripley12 3y agoIf you want to use grep in Nushell, you can use grep and pipe the output to `lines` to split the raw output by line.
- dwattttt 3y ago> If you just want a list of files in a POSIX shell you use a glob expression. I think this sums up the problem. If you want a list of files for display you use ls, and if you want it for other purposes use a glob; it seems much more elegant to have one way of getting files, and a separate way to format it for displaying if that's what you want.
- theamk 3y agoThat's already the case, just not the default. "ls -ld a*b file1.*" will use common way of getting files -- the glob expression; and "ls" will only be used to format the file list nicely. Except turns out people don't like to type extra characters, so the most common case, "ls -d *" is just "ls". Yes, shells (and command-line interface) have shortcuts to simplify typing. It's a feature, not a bug. I want to be able to type "ls -t" instead of "ls --sort=time", and any shell replacement which does not offer former option is doomed to fail.
- Ferret7446 3y agoI think most people choose a shell not based on its elegance, but whether it allows them to get things done.
- shirogane86x 3y agoAlong the lines of what another user said, you can actually get this a lot shorter. given variables $haystack and $needle, this actually becomes $haystack | lines | where $it =~ $needle which, albeit maybe not as concise as the grep solution, to me feels good enough, especially when you have so many other tools to handle text (all of the str subcommands, splitting by row/column and then working on tables). also, admittedly, if you want to drop down to "normal" ls, you are one character away: use a caret and you can drop down to the usual bash/sh/whatever.