News for hackers. Stuff that matters.
Re:GitHub – nushell/nushell: A new type of shell by j1elo on Wednesday June 16, 2021 @04:17AM (#27526147)
Am I missing something cool by not looking into PowerShell for Linux? Anyone using it could chime in and share how it improves their workflow? What kind of tools does it bring to the table?
Re:GitHub – nushell/nushell: A new type of shell by torginus on Wednesday June 16, 2021 @07:55AM (#27527491)
Disclaimer: I use PowerShell on Windows, I've never tried it on Linux, but I don't see why its advantages wouldn't transfer. That being said, I think it's main advantages are:

- Typed object streams, which gives you stuff like autocomplete, IDE support, and generally there's no need to muck about with sed/awk/xargs - Very fast, it's absolutely fine to read a file line by line, and parse it in a script, whereas doing the same in bash/awk is a ton slower than clever use of cat/grep/wc (and a myriad of other tools) - Due to type information being retained, it's a lot easier to figure out what a given script does, without having to know how the output of a given tool looks like, given it's particular command line switches.

This is just my opinion, but PowerShell is a lot more geared toward people like me, who only write a script once in a blue moon/muck about with the build scripts occasionally, while Bash is more geared toward veteran sysadmins who live and breathe this stuff.

Re:GitHub – nushell/nushell: A new type of shell by j1elo on Wednesday June 16, 2021 @08:42AM (#27527845)
Nice summary. It leaves me wonder, though: is the philosophy the same as in Unix world? as in, little independent tools that do one and just one thing. Would those tools also need to be modified to add compatibility with the same typing system that is used by the shell?

Or it follows the opposite mentality and the sell comes with batteries included?

I'm thinking of some arbitrary example, like downloading a JSON and parsing it to obtain some nested sub-property. In Bash world you would use the shell to execute at least something like `wget` to do the download part, and then run `jq` to parse the JSON and select the desired property. Both of `wget` and `jq` are independent programs, installed separately, with their own input & output channels, that you combine together by using the shell itself.

How would this work with PowerShell? (feel free to use some other example that might be better suited)

Re:GitHub – nushell/nushell: A new type of shell by naikrovek on Wednesday June 16, 2021 @09:14AM (#27528148)
Powershell commands (called "commandlets" or "cmdlets") are little .net (or .net core) programs/methods which accept and return either objects or arrays of objects, rather than plain text.

powershell offers cmdlets which let you sort and filter these result objects based on object property values rather than sorting on plain text values.

Obviously when printing to stdout or stderr, THAT bit is plain text, but until that very last step of displaying in the terminal, powershell results are objects.

So, that gives you a form of type safety, which isn't strictly possible in text-only shells. Powershell uses reflection to inspect the objects since the exact type of a response may have never been seen before. You can write your own cmdlets which return your own types and you can modify types returned by cmdlets using operators like 'select'. So, it's type-safe but not like everyone is used to. Powershell cmdlets always return objects (or errors, I guess), but the structure of those objects isn't always known until runtime. You can still use those never-before-seen types with the standard operators like sort and select, too.

Powershell also offers output conversion cmdlets which let you output to CSV or a textual table or a list, which is helpful when the next step in your pipe chain is a tool that expects textual input or a csv file. One can also write their own output formatters, of course.

In those ways, powershell and nushell appear to have the same goals. I haven't looked at nushell any more closely than it would take to notice this, so there may be other similarities I haven't noticed, yet. I'm sure there are many differences that I haven't noticed yet, as well.

Re:GitHub – nushell/nushell: A new type of shell by j1elo on Wednesday June 16, 2021 @10:49AM (#27529134)
Thank you very much, it's now clearer to me how it works.

Regarding the objects themselves, the way you describe them makes me think of Javascript objects & arrays: you don't need to know the exact shape of an input object, as long as it has the specific properties that you want to work on. Same for arrays: regardless of their content, the language allows you to use the standard ops like map() or find() (and it's then a matter of you providing adequate functions to access the contained elements)

Re:GitHub – nushell/nushell: A new type of shell by vips7L on Wednesday June 16, 2021 @09:13AM (#27528133)
In powershell you would use built ins.

To download json over rest you would use Invoke-RestMethod or irm.

To convert json to objects you would use ConvertFrom-Json.

To select properties from objects you would use Select-Object or select.

Here is a concrete example that I wrote for the rustlings install script: https://github.com/rust-lang/rustlings/blob/main/install.ps1...

Note that I used Invoke-WebRequest instead of irm here.

Re:GitHub – nushell/nushell: A new type of shell by d0mine on Saturday June 19, 2021 @04:52AM (#27558964)
It looks like: `curl <url> | jq .tag_name` Note: curl & jq are independent programs (as long as `curl` produce json text with tag_name in each, the command works, no matter other changes).

If ConvertFrom-Json & Select-Object were not builtin, how much information about each other would they need to cooperate? Can an unrelated change in ConvertFrom-Json's output break corresponding Select-Object command? How much are they intertangled?

Re:GitHub – nushell/nushell: A new type of shell by vips7L on Sunday June 20, 2021 @10:06PM (#27575594)
Curl to python is actually what happens in the Linux install script [0].

To your point, all cmdlets adhere to an interface so they always return and receive typed data. They don’t really need to know anything except that they’re receiving or giving powershell objects.

Non built in commands (native binaries) just pipe a stream of bytes just like any posix shell.

Re:GitHub – nushell/nushell: A new type of shell by bobalob_wtf on Saturday June 19, 2021 @09:49AM (#27560439)
ConvertFrom-Json converts json text into a PowerShell object with properties derived from the json.

Select-Object (in this instance) selects a property from the object.

An unrelated change in ConvertFrom-Json wouldn't change it's basic nature which is to convert json into something you can manipulate with other PowerShell cmdlets.

Re:GitHub – nushell/nushell: A new type of shell by j1elo on Wednesday June 16, 2021 @10:54AM (#27529184)
And then I guess the shell itself has mechanisms to easily attach or register new commandlets, to allow for easily add custom object processing?

I really like the consistency that those commands have: ConvertFrom-<ConverterFormat>.

No built in converter for the format you need? I'm just speculating here, but I guess you just need to implement this or that Interface and there you go.

Re:GitHub – nushell/nushell: A new type of shell by vips7L on Wednesday June 16, 2021 @11:55AM (#27529964)
Yes you can write your own cmdlets in either C# or powershell that you can install via modules [0]

You can also just write a function in your profile.

[0] https://docs.microsoft.com/en-us/powershell/scripting/develo...

Re:GitHub – nushell/nushell: A new type of shell by godtoldmetodoit on Wednesday June 16, 2021 @11:43AM (#27529821)
You can define your own function and use it in your pipeline yes. You can have your function take pipeline input just like the built in cmdlets.
Re:GitHub – nushell/nushell: A new type of shell by smackeyacky on Wednesday June 16, 2021 @04:45AM (#27526313)
I use it a bit on windows servers because it integrates well with other microsoft tools.

On linux...it seems both redundant and just plain weird for weirds sake. There are literally dozens of alternatives on linux that have a sane syntax and are likely preinstalled.

Re:GitHub – nushell/nushell: A new type of shell by yabones on Wednesday June 16, 2021 @08:33AM (#27527761)
Powershell is a pretty neat scripting language, especially if you manage Windows boxes or have lots of .net stuff around.

It's not a good interactive shell environment though. The commands are way too verbose and the syntax feels clunky for keying in.

Re:GitHub – nushell/nushell: A new type of shell by AnIdiotOnTheNet on Wednesday June 16, 2021 @09:24AM (#27528254)
I disagree. Yes, the syntax is verbose so that you get sensical names instead of things like 'awk' and 'grep', but that isn't a big deal because a) tab complete[0], and b) user-definable aliases.

[0] tab complete works on cmdlets, switches, and variables.

Re:GitHub – nushell/nushell: A new type of shell by Arnavion on Wednesday June 16, 2021 @02:59PM (#27532163)
And if one misses the short incomprehensible aliases, the common commandlets have those by default anyway. `cat` is `gc`, `grep` is `sls`, `ls` is `gci`, ...

Same for switches and parameters. You don't have to miss `rm -rf foo/`, it's just `ri -re -fo foo/`

Re:GitHub – nushell/nushell: A new type of shell by pxc on Thursday June 17, 2021 @12:34AM (#27536165)
I don't mind the verbosity at all, but PowerShell in my experience is painfully slow for interactive use, if you want the kind of niceness you can get with Fish, Zsh, or Elvish (fuzzy filtering, smart-case completion, any-order/substring completion, etc.).

The module system is also not great for distributing little configure snippets like Oh My Zsh or something, it's clunky and over-complicated for that.

Re:GitHub – nushell/nushell: A new type of shell by JadeNB on Wednesday June 16, 2021 @03:23PM (#27532392)
> [0] tab complete works on cmdlets, switches, and variables.

Isn't this how modern tab complete works everywhere? bash 5.1 (the shell I happen to be running right now, and which I mention because I think of its out-of-box tab completion as pretty basic) tab completes variables.

Re:GitHub – nushell/nushell: A new type of shell by Kipters on Wednesday June 16, 2021 @05:42AM (#27526635)
I don't use it as a shell on Linux/macOS (I don't think it's even really supported yet), but as a scripting environment it's been ok: the language is sane enough, you can use the .NET BCL if you need to and its behavior is consistent across platforms.

We use it for automation in our .NET codebase (which is being developed on both Windows and Linux) instead of bash scripts because of that and the fact it's preinstalled in the .NET SDK Docker images

Re:GitHub – nushell/nushell: A new type of shell by brushfoot on Wednesday June 16, 2021 @06:16AM (#27526824)
It's supported on Linux. It's one of the first packages I install on a fresh box lately.
Re:GitHub – nushell/nushell: A new type of shell by loulouxiv on Wednesday June 16, 2021 @05:56PM (#27533919)
What do you use it for generally ?
Re:GitHub – nushell/nushell: A new type of shell by brushfoot on Thursday June 17, 2021 @09:45AM (#27539486)
My default shell. Everything from manipulating XML to system administration. I'm a big fan of the object-based pipeline.

Quick examples:

- Accelerators for data and conversion tasks. For example, reading a file with `Get-Content` (or frequently in the shell, the alias `gc`) and parsing and converting into a traversable, queryable XML: `[xml]$myXml = gc my-file.xml`. Then you can go `$myXml.customers.firstName` or use an XPath query.

- To get the difference between two dates, `[DateTime]::Now - [DateTime]'2021-01-01'` returns a `TimeSpan` with the elapsed hours, days, etc. It parses the date string for you because of the `[DateTime]` before it.

- The cmdlets for system administration. For example, exporting processes that use more than 200 MB of RAM and their image paths to CSV: `Get-Process | where { $_.WorkingSet -gt 200000000 } | select ProcessName, Path | Export-Csv memory-hogs.csv`

Re:GitHub – nushell/nushell: A new type of shell by Tijdreiziger on Wednesday June 16, 2021 @11:21AM (#27529536)
I used PowerShell as my main shell for a few years (before WSL existed). My experience is that it's extremely tedious having to relearn every command 'the PowerShell way' if you already know your way around standard Unix commands (and I wasn't exactly a Unix guru either). When WSL dropped I switched and haven't looked back.

The only PowerShell tool I did love was posh-git [0]. Thankfully, someone has ported it to bash/zsh as posh-git-sh [1].

[0] https://github.com/dahlbyk/posh-git

[1] https://github.com/lyze/posh-git-sh

Re:GitHub – nushell/nushell: A new type of shell by e12e on Wednesday June 16, 2021 @06:04PM (#27533973)
I don't think so. Although, there seems to be small trend, especially with golang utilities - to shift from text toward json - or rather a "worst of both worlds" - docker is a prime example of this, eg:

  docker network inspect webservers -f '{{ range.Containers}}{{.IPv4Address}}{{end}}'
Once tools start down this path, I think powershell, or any shell built around primitives that work on tree structures, make more sense (ie: rather than cut, awk, grep-tools for printing named fields etc).

Must admit, I am no big fan of ps syntax - too verbose for interactive use - too unfriendly for scripting..

Re:GitHub – nushell/nushell: A new type of shell by tonyedgecombe on Wednesday June 16, 2021 @05:41AM (#27526629)
If you spend all day immersed in PowerShell on Windows then it might make sense to leverage that familiarity on Linux.

Also if you are managing Azure from Linux or macOS.

Re:GitHub – nushell/nushell: A new type of shell by Macha on Wednesday June 16, 2021 @07:03AM (#27527096)
Powershell has some interesting ideas about passing around objects rather than just text.

The unix way of text streams and tools to manipulate them are too ingrained that I haven't bothered to get in detail, but I hear some people are fans.