Replace default rm alias with rm function

Define rm to work more like Unix/Linux

* Support -r and -f flags also -rf or -fr
* Support specifying multiple paths to remove
This commit is contained in:
Kenneth Benzie 2024-12-13 21:56:06 +00:00
parent d219cd1479
commit 5ec851fe11
2 changed files with 25 additions and 1 deletions

View File

@ -2,3 +2,4 @@
Remove-Item Alias:curl
Remove-Item Alias:wget
Remove-Item Alias:cd
Remove-Item Alias:rm

View File

@ -13,4 +13,27 @@ function cd {
Set-Location -Path $Path
}
# TODO: Define rm to work with -rf and multiple entries
# Define rm to work like Unix/Linux
# * Support -r and -f flags also -rf or -fr
# * Support specifying multiple paths to remove
function rm {
Param (
[Parameter(
Mandatory=$true,
ValueFromRemainingArguments=$true
)][string[]]$Paths,
[switch]$F, [switch]$Force,
[switch]$R, [switch]$Recurse,
[switch]$RF, [switch]$FR
)
$Command = "Remove-Item"
if ($F -or $Force -or $RF -or $FR) {
$Command = "$Command -Force"
}
if ($R -or $Recurse -or $RF -or $FR) {
$Command = "$Command -Recurse"
}
foreach ($Path in $Paths) {
Invoke-Expression -Command "$Command $Path"
}
}