8000 Aliases and native utils name collision · Issue #567 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
Aliases and native utils name collision #567
@vors

Description

@vors

We have 24 conflicting names between PS aliases and /bin, /usr/bin, etc folders

# /bin
cat              
cp               
echo             
kill             
ls               
mv               
ps               
pwd              
rm               
rmdir            
sleep
# /usr/bin
cd                     
clear                  
cpp                    
diff                   
fc                     
man                    
ri                     
sort                   
tee                    
type                   
write         
# /usr/sbin
ac
# /sbin
mount

We need to figure out what's out story about it.

I think it make sense to play around with different options to see pros and cons on practice.

Try it (the snippet is outdated, see the new snippet for 0.3.0 bellow)

You can add this snippet to your profile and easily switch from one mode to another

  • Remove-PSAliases will remove aliases, so you can use native utilities.
  • Set-PSAliases will restore aliases.
$global:__aliases = @(
    'cat',              
    'cp',               
    'echo',             
    'kill',             
    'ls',               
    'mv',               
    'ps',               
    'pwd',              
    'rm',               
    'rmdir',            
    'sleep',
    'cd',                     
    'clear',                  
    'cpp',                    
    'diff',                   
    'fc',                     
    'man',                    
    'ri',                     
    'sort',                   
    'tee',                    
    'type',                   
    'write',         
    'ac',
    'mount'
) 

function Set-PSAliases
{
    $global:__aliases | % { 
        Write-Host "Adding $_"
        Set-Alias $_ $global:__aliases_backup[$_] -Scope Global 
    }      
}

function Remove-PSAliases
{
    if (-not $global:__aliases_backup) {
        $global:__aliases_backup = @{}
        $global:__aliases | % {
            $global:__aliases_backup[$_] = (Get-Command $_).ResolvedCommandName
        }
    }

    $global:__aliases | % { 
        Write-Host "Removing $_"
        while (Test-Path alias:$_) {
            Remove-Item -Force alias:$_ 
        }
    }
}

Metadata

Metadata

Assignees

Labels

Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aUsability(LEGACY) Helps filter issues that might be higher priority because they directly affect usability

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0