mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add the function cd~ (#18308)
This commit is contained in:
@@ -4709,6 +4709,7 @@ end {
|
||||
// Functions that don't require full language mode
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd..", "Set-Location ..", isProductCode: true, languageMode: systemLanguageMode),
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd\\", "Set-Location \\", isProductCode: true, languageMode: systemLanguageMode),
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd~", "Set-Location ~", isProductCode: true, languageMode: systemLanguageMode),
|
||||
// Win8: 320909. Retaining the original definition to ensure backward compatability.
|
||||
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Pause",
|
||||
string.Concat("$null = Read-Host '", CodeGeneration.EscapeSingleQuotedStringContent(RunspaceInit.PauseDefinitionString), "'"), isProductCode: true, languageMode: systemLanguageMode),
|
||||
|
||||
@@ -230,4 +230,36 @@ Describe "Set-Location" -Tags "CI" {
|
||||
$PWD.Path | Should -Be $location.Path
|
||||
}
|
||||
}
|
||||
|
||||
Context 'Parsing of Set-Location to cd' {
|
||||
It 'Should go to Filesystem home on cd~ run' {
|
||||
Set-Location 'TestDrive:\'
|
||||
cd~
|
||||
(Get-Location).Path | Should -BeExactly (Get-PSProvider FileSystem).Home
|
||||
}
|
||||
It 'Should go to the parent folder on cd.. run' {
|
||||
Set-Location 'TestDrive:\'
|
||||
$ParentDir = (Get-Location).path
|
||||
New-Item -Path 'TestDrive:\' -Name 'Directory1' -ItemType Directory
|
||||
Set-Location 'TestDrive:\Directory1'
|
||||
cd..
|
||||
(Get-Location).Path | Should -BeExactly $ParentDir
|
||||
}
|
||||
It 'Should go to root of current drive on cd\ run (Windows)' -Skip:(!$IsWindows){
|
||||
#root is / on linux and Mac, so it's not happy with this check.
|
||||
Set-Location 'TestDrive:\'
|
||||
$DriveRoot = (Get-Location).path
|
||||
New-Item -Path 'TestDrive:\Directory1' -Name 'Directory2' -ItemType Directory
|
||||
Set-Location 'TestDrive:\Directory1\Directory2'
|
||||
cd\
|
||||
(Get-Location).Path | Should -BeExactly $DriveRoot
|
||||
}
|
||||
It 'Should go to root of current drive on cd\ run (Linux/Mac)' -Skip:($IsWindows){
|
||||
Set-Location 'TestDrive:\'
|
||||
New-Item -Path 'TestDrive:\Directory1' -Name 'Directory2' -ItemType Directory
|
||||
Set-Location 'TestDrive:\Directory1\Directory2'
|
||||
cd\
|
||||
(Get-Location).Path | Should -BeExactly "/"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user