WindowsPowerShell/utils.ps1
Kenneth Benzie (Benie) 5ec851fe11 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
2024-12-13 22:09:44 +00:00

40 lines
1.0 KiB
PowerShell

# Define cd to work more like Unix/Linux:
# * No path argument changes to the users home directory
# * Passing "-" for the path argument changes to the previous directory
$Global:cdPreviousPath = Get-Location
function cd {
Param ([string]$Path)
if ($Path -eq "") {
$Path = "~"
} elseif ($Path -eq "-") {
$Path = $cdPreviousPath
}
$Global:cdPreviousPath = Get-Location
Set-Location -Path $Path
}
# 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"
}
}