by klodolph · 6y ago · 0 comments
- As an interactive shell, it suffers from an ecosystem which is much poorer than the bash/zsh ecosystem,
- As a scripting language, I’m going to use Python or Go the moment anything becomes larger than a few lines,
- Installing Posh Git is just a really mediocre experience (indicative of various, more specific problems)
Some of these things can be fixed up, like the bad experience installing Posh Git—you have to update the package manager to a non-release version, but the signature is occasionally broken (it seems to happen again and a gain) so you have to disable signature verification, and then you can use the updated package manager to download the Posh Git package.
Through the journey I encountered so many stupid random problems that it’s not something I can just step out and recommend to anyone. I’ll continue using it as my primary shell on Windows, but for various reasons (I forget the exact details) I had to give up on it for working with Git. There was a lot of “action at a distance”, like running ssh-agent would break the “ls” alias for Get-ChildItem, which leaves me high and dry without muscle memory.
Meanwhile, Microsoft is also spending time and money on WSL. Again, I’ll still be using PowerShell on Windows but even there it is a damn rough experience. The command-line has been paradoxically a second-class citizen as well as a necessary tool for development on Windows for as long as I can remember, and it will take a lot more improvement to PowerShell before that feeling disappears.
But maybe that's just a result if it being so new. 'ls' has been around for almost 50 years...
What it really feels like is a complete programming language inside of notepad.exe because of the historically terrible windows command prompt.
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete
Set-PSReadLineOption -ShowToolTips
Also note that you can get in-console help on most commands without having to go out to a web browser. On the ones I've tried, examples are also included which help output too.
Help will also list available commands; eg:
help json
Shows me the three commands available from my shell: ConvertFrom-Json, ConvertTo-Json and Test-Json.
There is also Get-Command, which you can filter for command discovery, ie:
Get-Command | where Name -Like "Json"
The advantage to PowerShell being object-based here is that if you press <TAB> after typing where, the list of completions you get will include the properties that are in the object returned as the result of Get-Command.
I also use Cmder for a much nicer console than cmd.exe. I haven't tried the latest version of the new Windows Terminal but I hear it's also nice.
This surprises me as I feel exactly the opposite.
I may not know how to manage X via PowerShell, but I know those pre-approved verbs like Get/Set/New/Test/Convert etc. Then I know commands from same module usually start with some abbreviation like Get-Net.... Then I can tab throguth commands.
Or just Get-Module (to see loaded/available modules) and then Get-Command -ModuleName x or just help tcp. And if "help Get-NetTCPSetting -Full" won't help, yeah, fallback to google.
Example. Now how would I set an IP address for an interface not having an idea? (where you see italicized, actually there are star-wildcard around the word)
1. help ip (ohh, too much results)
2. help set-ip - alright, Set-NetIPAddress
3. help Set-NetIPAddress -Examples (seems I need to specify some interface. It is probably at Get-NetIPInter<TAB> - ahh, gives me Get-NetIPInterface, here you are.)
4. Get-NetIPInterface
5. Set-NetIPInterface -<TAB><TAB><TAB> (autocompletes arguments and I choose which I would like to set or not)
It takes loads of reading and trial and error to become competent in any command line.
PS: the ISE (Integrated Scripting Environment) helps when writing scripts.
Even so, I don't think we can use that excuse given that it was released over 13 years ago...
I know all this is personal and subjective. I think using git to manage this is pretty easy and safe. If and when I want to update it’s as simple as doing a git pull in my local repo of posh-git and reloading the shell.
If the new version is broken (has never happened yet but ya know.. in case) just checkout the previous one.
I have found using git, the powershell user profile and modifying my user path when necessary is the best way of managing dev dependencies on Windows.
I also understand why people want this all abstracted away from them in a package manager.
* You have access to the entire .Net standard library
* Optional typing
* Writing functions and using pipes allows a functional style
* You can even inline some C# code, or read it from a separate file and compile it on the fly. I've used that to make windows API calls (P/Invoke).
Overall, I'd choose pwsh scripting over bash any day, and I'd say it doesn't even make me miss python all that much (for simple scripts, couple hundred lines max).The main feature lacking for larger scripts/tools is classes, I think. Unless it has changed in newer versions, powershell is object-oriented yet does not allow you to define custom classes, which is annoying to say the least. The workaround is loading c# on the fly.
The point is very much that with powershell this move is to C#, with a much nicer integration with the shell.
I always feel like things in power shell are harder then they need to be that other scripting languages I don’t have that problem. One thing I do like is being able to leverage .net locally and also import DLLs. That helps me get around a bunch of gaps.