Skip to content

Instantly share code, notes, and snippets.

@thinkbeforecoding
Created October 10, 2016 10:29

Revisions

  1. thinkbeforecoding created this gist Oct 10, 2016.
    28 changes: 28 additions & 0 deletions start.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    . $env:UserProfile\AppData\Local\GitHub\shell.ps1


    Function Start-SSHAgent{
    param(
    [Parameter(Mandatory=$false,ValueFromPipeline=$true)]
    [string]$socketfile="/tmp/.ssh-socket", # Used as input to ssh-agent, which expects POSIX format paths
    [Parameter(Mandatory=$false)]
    [string]$pidFile="$env:TEMP\.ssh-agent-pid" # Used as input to Out-File which expects Windows format paths
    )
    $env:SSH_AUTH_SOCK=$socketfile
    $agent_is_running = Get-Process | ? { $_.ProcessName -like "ssh-agent*"}
    if($agent_is_running -eq $null){
    rm $env:Temp\.ssh-socket -Force -ErrorAction SilentlyContinue
    $sshAgentOutput = ssh-agent -a $env:SSH_AUTH_SOCK
    $parse = Select-String -InputObject $sshAgentOutput -Pattern "(?m)SSH_AGENT_PID=(\d+)"
    $sshAgentPid = $parse.Matches[0].Groups[1].Value
    $sshAgentPid | Out-File $pidFile
    $env:SSH_AGENT_PID = $sshAgentPid
    }
    }

    #$r = ssh-agent -s
    #[regex]::Matches($r,"SSH_AUTH_SOCK=([^;]+);") | % { $env:SSH_AUTH_SOCK = $_.Groups[1] }
    #[regex]::Matches($r,"SSH_AGENT_PID=(\d+);") | % { $env:SSH_AGENT_PID = $_.Groups[1] }
    Start-SSHAgent

    ssh-add $env:UserProfile\.ssh\github_rsa