by kaba0 · 5y ago · 0 comments
What could potentially work for the linux world is perhaps dbus objects between piped programs (they are easy to read/write even from lower level languages) and some way for programs to communicate whether they are capable of interpreting objects, or should fall back to string based communication. And at the boundaries there could be automatic translations (though object to string is easier) with something like toString.
So for example `ls -la | filter f -> f.date > 2021-01-01 | grep something` would either shadow ls to a new shell-aware implementation or patch it /interpret automagically the table layout and then the resulting list of objects could be filtered and at the end reconverted to an object “toString” per each line which can be operated on by grep
You're not far away with how PowerShell can parse Linux commands. Instead of relying on awk/grep, PowerShell uses .NET under the hood to provide consistency across operating systems. There are a few methods for converting from a Linux command to PowerShell objects based on delimiters or OFS. If you're interested, Steve Lee wrote a blog post that does a good job covering how to parse Linux command output into PowerShell objects [1].
[0] https://docs.microsoft.com/en-us/powershell/scripting/instal...
[1] https://devblogs.microsoft.com/powershell/parsing-text-with-...
Thanks for the links though, I didn’t dive this deep into it.
M 0.12.7 jao@cheese ~$ import datetime datetime
M 0.12.7 jao@cheese ~$ ls | select (f: f.mtime > datetime(2021, 1, 1).timestamp()) | grep py
.marcel.py
.python_history
ls is builtin (and has -la behavior by default), select is provided by marcel, and grep is from the host OS. Note that the python function datetime.datetime is imported so that it can be used in the select predicate.If I may, PS is a first-class citizen on Linux, macOS, and Windows. PowerShell is a spectacular cross-platform shell that provides an object oriented paradigm and it's available today.