48 lines
1.1 KiB
PowerShell
48 lines
1.1 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"
|
|
}
|
|
}
|
|
|
|
# Define touch to create a new empty text file
|
|
function touch {
|
|
Param (
|
|
[string]$Path
|
|
)
|
|
New-Item -Type File $Path
|
|
}
|