public
Created

powershell script to start the ssh-agent

  • Download Gist
start-sshagent
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
$ gcm start-sshagent | fl
 
 
Name : start-sshagent
CommandType : Function
Definition :
if($env:SSH_AGENT_PID) { echo "ssh-agent running"; return }
$private:gp = get-gitbinpath
if($private:gp) {
$private:out = & (join-path $private:gp "ssh-agent")
$private:out | ?{$_.contains("=")} | %{
$private:cur = $_.split(";")[0]
$private:pair = $private:cur.split("=")
$private:cmd = ('$env:{0}="{1}"' -f $private:pair)
invoke-expression $private:cmd
}
write-warning "Use exit to leave shell"
register-engineevent powershell.exiting -action {
ps -Id $env:SSH_AGENT_PID -ErrorAction SilentlyContinue | stop-process
} | out-null
}
 
 
 
 
$ gcm addkey-sshagent | fl
 
 
Name : addkey-sshagent
CommandType : Function
Definition :
if($env:SSH_AGENT_PID) {
$private:gp = get-gitbinpath
if($private:gp) {
& (join-path $private:gp "ssh-add") (join-path $env:USERPROFILE "/.ssh/id_rsa")
}
}
 
 
 
$ gcm get-gitbinpath | fl
 
 
Name : get-gitbinpath
CommandType : Function
Definition :
$private:gp = (gcm git -ErrorAction SilentlyContinue)
if($private:gp) {
$private:pth = split-path (split-path $private:gp.Definition)
return join-path $private:pth "bin"
}
return $null

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.