Recently, I've started trying to join open source projects using my Windows PC and I like to keep to use PowerShell as my shell environment.
But, unfortunately, some open source projects don't care of PowerShell users maybe because the number of PowerShell users is quite fewer than Bash (or other Unix shells).
For example, sometime NodeJS project includes these kind of package.json, and we can't execute npm run clean
. PowerShell gives an alias to Remove-Item
for rm
, but its command options aren't compatible with rm
's one.
"scripts": {
"clean": "rm -rf ./build ./types"
}
Of course, we can use WSL2 or Cygwin, but I think PowerShell is a good shell and I want to learn about it. Why am I need to change my shell.
I'll write down here what I did for me who is forgatable.
I've decided to use shx. We can easily make the above package.json snippet cross-platform compatible.
"scripts": {
"clean": "shx rm -rf ./build ./types"
}
I updated the package.json and created a PR.
I wanted to keep to create another PR to implement a proposal of a new feature before the PR is merged. To do that, I wrrapped rm
command using shx
in my PowerShell profile file.
del Alias:rm -Force -ErrorAction Ignore
del Function:SHX-RM -ErrorAction Ignore
function global:SHX-RM {
shx rm @args
}
New-Alias rm SHX-RM -Force -Scope Global
I think we can take the same approach for other Unix specific commands.
PowerShell 5, which is installed as a default one for Windows 10 at this moment, doesn't support &&
and ||
. Recent version PowerShell, which is 7, supports it. So I installed new one in addition to the default one.
- https://github.com/shelljs/shx
- https://devblogs.microsoft.com/scripting/powertip-reload-your-powershell-profile/
- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-7.1
- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions?view=powershell-7.1
- https://stackoverflow.com/questions/4166370/how-can-i-write-a-powershell-alias-with-arguments-in-the-middle
- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/set-alias?view=powershell-7.1