Skip to content

Instantly share code, notes, and snippets.

@Razzile
Last active November 2, 2019 13:03
Show Gist options
  • Select an option

  • Save Razzile/f7c11dfd98fcb32fcdb9d5449c2a7fc6 to your computer and use it in GitHub Desktop.

Select an option

Save Razzile/f7c11dfd98fcb32fcdb9d5449c2a7fc6 to your computer and use it in GitHub Desktop.

Revisions

  1. Razzile revised this gist Nov 2, 2019. 1 changed file with 36 additions and 1 deletion.
    37 changes: 36 additions & 1 deletion user_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -78,8 +78,43 @@ function Launch-App {
    }
    }

    # Try load visual studio environment variables by default
    function Import-VSEnvironment {
    Write-Output "Setting up Visual Studio Developer Environment..."
    if (Get-Command "vswhere.exe" -errorAction SilentlyContinue) {
    $installationPath = vswhere.exe -latest -property installationPath
    if ($installationPath -and (Test-Path "$installationPath\Common7\Tools\vsdevcmd.bat")) {
    $json = $(& "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -no_logo -arch=x64 && powershell -Command `"Get-ChildItem env: | Select-Object Key,Value | ConvertTo-Json`"")
    if ($LASTEXITCODE -ne 0) {
    Write-Error "($LASTEXITCODE) $installationPath\Common7\Tools\vsdevcmd.bat: $json"
    }
    else {
    # Write-Host $json
    $($json | ConvertFrom-Json) | ForEach-Object {
    $k, $v = $_.Key, $_.Value
    Set-Content env:\"$k" "$v"
    }
    }
    }
    else {
    Write-Error "Cannot find 'vsdevcmd.bat' in installation directory [$installationPath\Common7\Tools\vsdevcmd.bat]"
    }
    }
    else {
    Write-Error "Executable 'vswhere' not found in PATH"
    }
    }

    function Create-File {
    param ([parameter(mandatory = $true)][ValidateNotNullOrEmpty()][string[]]$name)
    New-Item $name -type file
    }

    # set an alias for Launch-App
    Set-Alias -Name launch -Value Launch-App

    # set an alias for Import-VSEnvironment
    Set-Alias -Name vsenv -Value Import-VSEnvironment
    # set an alias for Create-File
    Set-Alias -Name new -Value Create-File
    # use proj variable as shorthand for $env:proj
    $proj = $env:proj
  2. Razzile revised this gist Jun 26, 2019. No changes.
  3. Razzile created this gist Jun 26, 2019.
    85 changes: 85 additions & 0 deletions user_profile.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,85 @@
    # Use this file to run your own startup commands

    ## Prompt Customization
    <#
    .SYNTAX
    <PrePrompt><CMDER DEFAULT>
    λ <PostPrompt> <repl input>
    .EXAMPLE
    <PrePrompt>N:\Documents\src\cmder [master]
    λ <PostPrompt> |
    #>

    #Import chocolatey helpers
    $ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
    if (Test-Path($ChocolateyProfile)) {
    Import-Module "$ChocolateyProfile"
    }

    [ScriptBlock]$PrePrompt = {

    }

    # Replace the cmder prompt entirely with this.
    [ScriptBlock]$CmderPrompt = {
    $Host.UI.RawUI.ForegroundColor = "Gray"

    # Workaround to make above line apply the "White" foreground color.
    # Seems like you have to print _something_ before using Write-Host with -ForegroundColor.
    # Note: Empty string "" doesn't work.
    Write-Host "`r" -NoNewline

    Microsoft.PowerShell.Utility\Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
    Microsoft.PowerShell.Utility\Write-Host (checkGit($pwd.ProviderPath)) -NoNewLine
    }

    [ScriptBlock]$PostPrompt = {

    }

    ## <Continue to add your own>

    <#
    Launch-App launches an app with a name that matches the provided string. wildcards are supported
    #>
    function Launch-App {
    param(
    [parameter(mandatory = $true)][ValidateNotNullOrEmpty()][string[]]$appname,
    [switch] $admin
    )
    $apps = (New-Object -Com Shell.Application).NameSpace('shell:::{4234d49b-0245-4df3-b780-3893943456e1}').Items()
    if ($apps) {
    $count = 0
    foreach ($app in $apps) {
    if ($app.Name -like $appname) {
    $count++
    if ($admin) {
    #"Run as administrator" action
    $action = $app.Verbs() | ? { $_.Name.replace('&', '') -eq "Run as administrator" }
    }
    else {
    # "Open" action
    $action = $app.Verbs() | ? { $_.Name.replace('&', '') -eq "Open" }
    }
    if ($action) {
    $action.DoIt()
    }
    else {
    Write-Error "Application '$appname' doesn't support this action."
    }
    }
    }
    if ($count -eq 0) {
    Write-Error "Application '$appname' Not Found."
    }
    }
    else {
    Write-Error "An unexpected error has occurred."
    }
    }

    # set an alias for Launch-App
    Set-Alias -Name launch -Value Launch-App

    # use proj variable as shorthand for $env:proj
    $proj = $env:proj