Created
          October 1, 2025 13:27 
        
      - 
      
- 
        Save guneysus/8ef5bec263194a63f5565d78a9586655 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <# | |
| .SYNOPSIS | |
| Create wrapper powershell functions or shortuts to your applications optionally with default values. | |
| .DESCRIPTION | |
| Long description | |
| .PARAMETER name | |
| Parameter description | |
| .PARAMETER path | |
| Parameter description | |
| .EXAMPLE | |
| add-wrapper "hugo" "C:\bin\hugo_0.135.0.exe" | |
| .EXAMPLE | |
| add-wrapper "ack" "perl" "$HOME\scoop\apps\ack\current\ack-single-file", "--ignore-dir=bin", "--ignore-dir=obj" | |
| .EXAMPLE | |
| add-wrapper "chrome-personal" "C:\Program Files\Google\Chrome\Application\chrome.exe" | |
| .EXAMPLE | |
| add-wrapper "chrome-automated" "C:\Program Files\Google\Chrome\Application\chrome.exe" "--enable-automation","other","extra", "arguments" | |
| .EXAMPLE | |
| xalias "exec" pwsh -noprofile, -nologo | |
| .NOTES | |
| General notes | |
| STDIN redirection does not work as expected. | |
| So this may not work: | |
| xalias "exec" pwsh "-noprofile", -nologo, -command, - | |
| #> | |
| function Set-Wrapper { | |
| [Alias("xalias")] | |
| param ( | |
| [Parameter(Mandatory = $true)][string]$name, | |
| [Parameter(Mandatory = $true)][string]$path, | |
| [Parameter(Mandatory = $false)][string[]]$defaultArgs | |
| ) | |
| # Check if we need to handle stdin | |
| $stdinRedirect = if ($defaultArgs -contains '-') { | |
| '$input | &' | |
| } | |
| else { | |
| '&' | |
| } | |
| $functionBody = "$stdinRedirect ""$path"" $($defaultArgs) `$args" | |
| # Store wrapper info in global variable | |
| if (-not (Test-Path variable:global:Wrappers)) { | |
| $Global:Wrappers = @{} | |
| } | |
| $Global:Wrappers[$name] = @{ | |
| Name = $name | |
| Body = $functionBody | |
| } | |
| # write-host -ForegroundColor Green $functionBody | |
| new-item -path function:\ -name "global:$name" -value $functionBody -Force | Out-Null | |
| } | |
| <# | |
| .SYNOPSIS | |
| Short description | |
| .DESCRIPTION | |
| Long description | |
| .EXAMPLE | |
| An example | |
| .NOTES | |
| General notes | |
| #> | |
| function Get-Wrappers { | |
| [Alias("wrappers")] | |
| param() | |
| if (-not (Test-Path variable:global:Wrappers)) { | |
| Write-Warning "No wrappers defined" | |
| return | |
| } | |
| $Global:Wrappers.GetEnumerator() | ForEach-Object { | |
| [PSCustomObject]@{ | |
| Name = $_.Value.Name | |
| Body = $_.Value.Body | |
| } | |
| } | Format-Table -AutoSize | |
| } | |
| # new-alias vs "C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\devenv.exe" | |
| # set-wrapper cpuz "C:\apps\cpuz.exe" | |
| # set-wrapper compile-lisp "C:\Program Files\Steel Bank Common Lisp\sbcl.exe" | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment