diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 6fa242ce521..34e5c6d7abb 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -4709,6 +4709,7 @@ internal static SessionStateAliasEntry[] BuiltInAliases // 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), diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 index 2fb8177ec1a..f8a15d389e3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Set-Location.Tests.ps1 @@ -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 "/" + } + } }