Skip to content

Commit

Permalink
Merge pull request #786 from PowerShell/andschwa/remove-aliases
Browse files Browse the repository at this point in the history
Fix aliases
  • Loading branch information
andyleejordan committed Apr 8, 2016
2 parents d260131 + 73fe95f commit 3582bb4
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 131 deletions.
110 changes: 62 additions & 48 deletions src/System.Management.Automation/engine/InitialSessionState.cs
Expand Up @@ -5121,8 +5121,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases
"Where-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("?",
"Where-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("ac",
"Add-Content", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("clc",
"Clear-Content", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cli",
Expand All @@ -5131,26 +5129,18 @@ internal static SessionStateAliasEntry[] BuiltInAliases
"Clear-ItemProperty", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("clv",
"Clear-Variable", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("compare",
"Compare-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cpi",
"Copy-Item", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cpp",
"Copy-ItemProperty", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cvpa",
"Convert-Path", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("dbp",
"Disable-PSBreakpoint", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("diff",
"Compare-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("ebp",
"Enable-PSBreakpoint", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("epal",
"Export-Alias", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("epcsv",
"Export-Csv", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("fc",
"Format-Custom", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("fl",
"Format-List", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("ft",
Expand Down Expand Up @@ -5260,26 +5250,75 @@ internal static SessionStateAliasEntry[] BuiltInAliases
"Set-Item", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("sl",
"Set-Location", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("sleep",
"Start-Sleep", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("sort",
"Sort-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("sp",
"Set-ItemProperty", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("saps",
"Start-Process", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("start",
"Start-Process", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("spps",
"Stop-Process", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("spsv",
"Stop-Service", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("sv",
"Set-Variable", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
// Porting note: #if !LINUX is used to disable alises for cmdlets which conflict with Linux / OS X
#if !LINUX
// ac is a native command on OS X
new SessionStateAliasEntry("ac",
"Add-Content", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("compare",
"Compare-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cpp",
"Copy-ItemProperty", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("diff",
"Compare-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("sleep",
"Start-Sleep", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("sort",
"Sort-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("start",
"Start-Process", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("tee",
"Tee-Object", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("write",
"Write-Output", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
// These were traqnsferred from the "transferred from the profile" section
new SessionStateAliasEntry("cat",
"Get-Content", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cp",
"Copy-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("ls",
"Get-ChildItem", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("man",
"help", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("mount",
"New-PSDrive", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("mv",
"Move-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("ps",
"Get-Process", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("rm",
"Remove-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("rmdir",
"Remove-Item", "", ScopedItemOptions.AllScope),
#endif
// Bash built-ins we purposefully keep even if they override native commands
new SessionStateAliasEntry("cd",
"Set-Location", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("dir",
"Get-ChildItem", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("echo",
"Write-Output", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("fc",
"Format-Custom", "", ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),
new SessionStateAliasEntry("kill",
"Stop-Process", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("pwd",
"Get-Location", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("type",
"Get-Content", "", ScopedItemOptions.AllScope),
// Native commands we keep because the functions act correctly on Linux
new SessionStateAliasEntry("clear",
"Clear-Host", "", ScopedItemOptions.AllScope),
//#if !CORECLR is used to disable aliases for cmdlets which are not available on OneCore
#if !CORECLR
new SessionStateAliasEntry("asnp",
Expand Down Expand Up @@ -5316,46 +5355,18 @@ internal static SessionStateAliasEntry[] BuiltInAliases
"Out-Printer", "", ScopedItemOptions.AllScope),
#endif
// Aliases transferred from the profile
new SessionStateAliasEntry("cat",
"Get-Content", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cd",
"Set-Location", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("clear",
"Clear-Host", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cp",
"Copy-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("h",
"Get-History", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("history",
"Get-History", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("kill",
"Stop-Process", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("ls",
"Get-ChildItem", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("man",
"help", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("mount",
"New-PSDrive", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("md",
"mkdir", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("mv",
"Move-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("popd",
"Pop-Location", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("ps",
"Get-Process", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("pushd",
"Push-Location", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("pwd",
"Get-Location", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("r",
"Invoke-History", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("rm",
"Remove-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("rmdir",
"Remove-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("echo",
"Write-Output", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("cls",
"Clear-Host", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("chdir",
Expand All @@ -5364,8 +5375,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases
"Copy-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("del",
"Remove-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("dir",
"Get-ChildItem", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("erase",
"Remove-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("move",
Expand All @@ -5376,8 +5385,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases
"Rename-Item", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("set",
"Set-Variable", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("type",
"Get-Content", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("icm",
"Invoke-Command", "", ScopedItemOptions.AllScope),
new SessionStateAliasEntry("clhy",
Expand Down Expand Up @@ -5460,12 +5467,18 @@ internal static SessionStateAliasEntry[] BuiltInAliases
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("prompt", DefaultPromptFunctionText),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("TabExpansion2", TabExpansionFunctionText),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Clear-Host", GetClearHostFunctionText()),
// Porting note: we keep more because the function acts correctly on Linux
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("more", DefaultMoreFunctionText),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("help", GetHelpPagingFunctionText()),
// Porting note: we remove mkdir on Linux because it is a conflict
#if !LINUX
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("mkdir", GetMkdirFunctionText()),
#endif
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Get-Verb", GetGetVerbText()),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("oss", GetOSTFunctionText()),

// Porting note: we remove the drive functions from Linux because they make no sense
#if !LINUX
// Default drives
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("A:", DefaultSetDriveFunctionText, SetDriveScriptBlock),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("B:", DefaultSetDriveFunctionText, SetDriveScriptBlock),
Expand Down Expand Up @@ -5493,6 +5506,7 @@ internal static SessionStateAliasEntry[] BuiltInAliases
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("X:", DefaultSetDriveFunctionText, SetDriveScriptBlock),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Y:", DefaultSetDriveFunctionText, SetDriveScriptBlock),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Z:", DefaultSetDriveFunctionText, SetDriveScriptBlock),
#endif

SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd..", "Set-Location .."),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("cd\\", "Set-Location \\"),
Expand Down
29 changes: 0 additions & 29 deletions test/powershell/Compare-Object.Tests.ps1
Expand Up @@ -35,35 +35,6 @@ Describe "Compare-Object" {
{ Compare-Object -ReferenceObject $(Get-Content $file1) $(Get-Content $file2) } | Should Not Throw
}

It "Should be able to execute compare object using the compare alias" {
{ compare -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
}

It "Should produce the same output when the compare alias is used" {
$alias = compare -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$fullname = Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)

$alias[0].InputObject | Should Be $fullname[0].InputObject
$alias[0].SideIndicator | Should Be $fullname[0].SideIndicator
$alias[1].InputObject | Should Be $fullname[1].InputObject
$alias[1].SideIndicator | Should Be $fullname[1].SideIndicator

$alias.Length | Should Be 2 # There should be no other elements to test

}

It "Should be able to execute compare object using the diff alias" {
$alias = diff -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)
$fullname = Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2)

$alias[0].InputObject | Should Be $fullname[0].InputObject
$alias[0].SideIndicator | Should Be $fullname[0].SideIndicator
$alias[1].InputObject | Should Be $fullname[1].InputObject
$alias[1].SideIndicator | Should Be $fullname[1].SideIndicator

$alias.Length | Should Be 2 # There should be no other elements to test
}

It "Should indicate data that exists only in the reference dataset" {
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)

Expand Down
19 changes: 19 additions & 0 deletions test/powershell/Default-Aliases.Tests.ps1
@@ -0,0 +1,19 @@
$removeAliasList = @("ac","compare","cpp","diff","sleep","sort","start","cat","cp","ls","man","mount","mv","ps","rm","rmdir")
$keepAliasList = @{cd="Set-Location"},@{dir="Get-ChildItem"},@{echo="Write-output"},@{fc="format-custom"},@{kill="stop-process"},@{clear="clear-host"}
Describe "Windows aliases do not conflict with Linux commands" {
foreach ($alias in $removeAliasList) {
It "Should not have certain aliases on Linux" -Skip:$IsWindows {
Test-Path Alias:$alias | Should Be $false
}
}

foreach ($alias in $keepAliasList) {
It "Should have aliases that are Bash built-ins on Linux" {
(Get-Alias $alias.Keys).Definition | Should Be $alias.Values
}
}

It "Should have more as a function" {
Test-Path Function:more | Should Be $true
}
}
2 changes: 1 addition & 1 deletion test/powershell/Export-Alias.Tests.ps1
Expand Up @@ -144,7 +144,7 @@ Describe "Export-Alias" {

Test-Path $fulltestpath | Should Be $true

$actual = Get-Content $fulltestpath | Sort
$actual = Get-Content $fulltestpath | Sort-Object
$expected = Get-Command -CommandType Alias

for ( $i=0; $i -lt $expected.Length; $i++)
Expand Down
4 changes: 0 additions & 4 deletions test/powershell/Get-ChildItem.Tests.ps1
Expand Up @@ -9,10 +9,6 @@ Describe "Get-ChildItem" {
popd
}

It "Should be able to use the ls alias" {
$(ls .).Name.Length | Should Be $(Get-ChildItem .).Name.Length
}

It "Should have a the proper fields and be populated" {
$var = Get-Childitem .

Expand Down
12 changes: 3 additions & 9 deletions test/powershell/Get-Content.Tests.ps1
Expand Up @@ -40,10 +40,6 @@ Describe "Get-Content" {
(Get-Content -Path $testPath) | Should Be $testString
}

It "Should be able to call using the cat alias" {
{ cat -Path $testPath } | Should Not Throw
}

It "Should be able to call using the gc alias" {
{ gc -Path $testPath } | Should Not Throw
}
Expand All @@ -55,11 +51,9 @@ Describe "Get-Content" {
It "Should return the same values for aliases" {
$getContentAlias = Get-Content -Path $testPath
$gcAlias = gc -Path $testPath
$catAlias = cat -Path $testPath
$typeAlias = type -Path $testPath

$getContentAlias | Should Be $gcAlias
$getContentAlias | Should Be $catAlias
$getContentAlias | Should Be $typeAlias
}

Expand All @@ -68,21 +62,21 @@ Describe "Get-Content" {
}

It "Should be able to specify the number of lines to get the content of using the TotalCount switch" {
$returnArray = (cat -Path $testPath2 -TotalCount 2)
$returnArray = (Get-Content -Path $testPath2 -TotalCount 2)

$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}

It "Should be able to specify the number of lines to get the content of using the Head switch" {
$returnArray = (cat -Path $testPath2 -Head 2)
$returnArray = (Get-Content -Path $testPath2 -Head 2)

$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
}

It "Should be able to specify the number of lines to get the content of using the First switch" {
$returnArray = (cat -Path $testPath2 -First 2)
$returnArray = (Get-Content -Path $testPath2 -First 2)

$returnArray[0] | Should Be $firstline
$returnArray[1] | Should Be $secondline
Expand Down

0 comments on commit 3582bb4

Please sign in to comment.