should powershell provide a cross platform scriptable file editor? #19999
Replies: 5 comments 4 replies
-
I love it and I really like being able to specify multiple actions. Feels a bit like manipulating a document via an editor's API. I wonder if there could be a simple way to do Edit-File -file /etc/resolv.conf -action Replace -Pattern "^(?<=nameserver\s).*" -Replacement "8.8.8.8"
|
Beta Was this translation helpful? Give feedback.
-
I wrote something similar and I like syntax like this: XMLShould-Be $OpenDentalXml "/ConnectionSettings/DatabaseConnection/ComputerName" -Value $Hostname -Set
XMLShould-Be $OpenDentalXml "/ConnectionSettings/DatabaseConnection/Database" -Value $Database -Set I have a similar one for INI files I tried to do something similar with JSON but there doesn't appear to be built in .net support for JsonPath yet I just like the idea of using native format handlers instead of just regex |
Beta Was this translation helpful? Give feedback.
-
There's a part of me that looked at the example and thought: oh man, the "PowerShell is too verbose" people are going to have a field day ... but honestly, I'm just never going to get tired of saying: yeah, but you can tell what this does, even though you've never tried it! So I like the idea, and I like the readability -- but I want it to be blindingly fast at the core automation functionality like (regex) search and replace. As far as the example, personally, I would prefer an Actions syntax more like a macro DSL, and less like a JSON list. I think it would be more readable and less typing: SearchForward -Pattern "#PasswordAuthentication"
Replace -Pattern "#PasswordAuthentication.*" -Replacement "PasswordAuthentication`tyes" -Predicate PreviousSuccess
Position -Position Begin
SearchForward -Pattern "^Subsystem.*Powershell"
... If it's going to have an interactive mode, I want it to at least have syntax highlighting (e.g. via textmate grammars), and in the interest of usability, I personally think it should always have a (status) bar when it starts (like On that note, I think you need to consider and be clear, up front, about what the priorities for the project are. E.g.: what's most important: speed vs code readability, speed vs features, automation vs interaction ... |
Beta Was this translation helpful? Give feedback.
-
Powershell is the best engine in the world, and I use it to make the best cars. Powershell fans:
Its search and replacement do not support regularization. Supports SSH, WinRM, and remote work. download to local and translate https://gitee.com/chuanjiao10/kasini3000/blob/master/node_script/kasini3000/psed.ps1 /path/psed.ps1 -infile /tmp/a.txt -find 'SELINUX=disabled' -replace 'xxx1' |
Beta Was this translation helpful? Give feedback.
-
Looks cool like a Should there be a way to ignore case or replace a certain occurrence of a pattern? Are there any other features of I agree that it should be fast. And I would want to see tab completion on the actions. And I'd like to see less verbose usage for advanced users who are working interactively. |
Beta Was this translation helpful? Give feedback.
-
The platforms have had scriptable editors for ever. Unix had
ed
and for Windows it wasedlin
. Both of these tools are pretty arcane from a usage perspective, but they filled a need. When PS first started out on Windows, most configuration was found in the registry but there still were opportunities to automate editing files. When we went cross platform, there are more opportunities for file editing (I've found myself scriptinged
on more than a couple instances). Those of us that have needed this usually write a bit of bespoke code to handle it. I know that @rkeithhill started down this path as well (there's an old PR of his in the textutility module).Should PowerShell provide a similar experience (but perhaps less arcane, and perhaps more verbose)?
I've been working on a possible approach for this and I call it (creatively enough)
Edit-File
. I was inspired byed
and It works by taking discrete actions and allow you to aggregate them into a set of editing instructions.Here's an example of how it works - editing the
sshd_config
file.It should be pretty obvious what it does. Is this interesting? useful? could it be?
Beta Was this translation helpful? Give feedback.
All reactions