Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module posh-git
- function Set-ParamAlias {
- param
- (
- [string]$Name,
- [string]$Command,
- [hashtable]$parametersBinding
- )
- function AddLine($ProxyCommand, $line) {
- $ProxyCommand -replace '(.*)(\$outBuffer = \$null)(.*)', "`$1`$2`n $line`$3"
- }
- $metadata = New-Object System.Management.Automation.CommandMetaData (Get-Command $Command)
- foreach ($b in $parametersBinding.GetEnumerator())
- {
- $null = $metadata.Parameters.Remove($b.Name)
- }
- $ProxyCommand = [System.Management.Automation.ProxyCommand]::Create($metadata)
- foreach ($b in $parametersBinding.GetEnumerator())
- {
- $ProxyCommand = AddLine $ProxyCommand "`$PSBoundParameters['$($b.Name)'] = $($b.Value)"
- }
- iex "function global:$Name { $ProxyCommand }"
- }
- Set-ParamAlias -Name rmr -Command rm -parametersBinding @{Recurse = '$true'; Force = '$true'}
- Set-ParamAlias -Name cpr -Command cp -parametersBinding @{Recurse = '$true'; Force = '$true'}
- Set-ParamAlias -Name mkfile -Command New-Item -ItemType file -parametersBinding @{Name = '$params'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement