diff --git a/alias.ps1 b/alias.ps1 index 63108ad..27fa16a 100644 --- a/alias.ps1 +++ b/alias.ps1 @@ -2,3 +2,4 @@ Remove-Item Alias:curl Remove-Item Alias:wget Remove-Item Alias:cd +Remove-Item Alias:rm diff --git a/utils.ps1 b/utils.ps1 index c4758d0..0e01f4f 100644 --- a/utils.ps1 +++ b/utils.ps1 @@ -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" + } +}