PoshCode Archive  Artifact [f3873af070]

Artifact f3873af070c8563bdd70eb0a88b9005128158cd3b77aea2a5bd8b25735d426b2:

  • File Bash-Aliases.ps1 — part of check-in [d347a8daf9] at 2018-06-10 13:08:49 on branch trunk — This is an old script I had lying around. It has NOT been updated in a long time :) (user: unknown size: 1536)

# encoding: ascii
# api: powershell
# title: Bash Aliases
# description: This is an old script I had lying around. It has NOT been updated in a long time :)
# version: 0.1
# type: module
# license: CC0
# function: Get-AliasFor
# x-poshcode-id: 2330
# x-archived: 2010-11-02T18:10:56
#
#
## Aliases Module, Bash-style aliases with functions
function alias {
   # pull together all the args and then split on =
   $alias,$cmd = [string]::join(" ",$args).split("=",2) | % { $_.trim()}

   if($Host.Version.Major -ge 2) {
      $cmd = Resolve-Aliases $cmd
   }
   New-Item -Path function: -Name "Global:Alias$Alias" -Options "AllScope" -Value @"
Invoke-Expression '$cmd `$args'
###ALIAS###
"@

   Set-Alias -Name $Alias -Value "Alias$Alias" -Description "A UNIX-style alias using functions" -Option "AllScope" -scope Global -passThru
}

function unalias([string]$Alias,[switch]$Force){ 
   if( (Get-Alias $Alias).Description -eq "A UNIX-style alias using functions" ) {
      Remove-Item "function:Alias$Alias" -Force:$Force
      Remove-Item "alias:$alias" -Force:$Force
      if($?) {
         "Removed alias '$Alias' and accompanying function"
      }
   } else {
      Remove-Item "alias:$alias" -Force:$Force
      if($?) {
         "Removed alias '$Alias'"
      }
   }
}

function Get-AliasFor([string]$CommandName) {
  ls Alias: | ?{ $_.Definition -match $CommandName }
}

# Export the public functions using Export-ModuleMember cmdlet
Export-ModuleMember alias,unalias,Get-AliasFor