From b49371eaa3acbea624c9250e79d35f1407ce4976 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Fri, 13 Dec 2024 21:56:06 +0000 Subject: [PATCH] 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 --- alias.ps1 | 1 + utils.ps1 | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) 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..e840538 100644 --- a/utils.ps1 +++ b/utils.ps1 @@ -13,4 +13,24 @@ function cd { Set-Location -Path $Path } -# TODO: Define rm to work with -rf and multiple entries +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" + } +}