-
-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90573f3
commit 1b157e9
Showing
8 changed files
with
236 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
function Get-SshPath($File = 'id_rsa') { | ||
# Avoid paths with path separator char since it is different on Linux/macOS. | ||
# Also avoid ~ as it is invalid if the user is cd'd into say cert:\ or hklm:\. | ||
# Also, apparently using the PowerShell built-in $HOME variable may not cut it for msysGit with has different | ||
# ideas about the path to the user's home dir e.g. /c/Users/Keith | ||
# $homePath = Invoke-NullCoalescing $Env:HOME $Home | ||
$homePath = if ($Env:HOME) {$Env:HOME} else {$Home} | ||
Join-Path $homePath (Join-Path .ssh $File) | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Add a key to the SSH agent | ||
.DESCRIPTION | ||
Adds one or more SSH keys to the SSH agent. | ||
.EXAMPLE | ||
PS C:\> Add-SshKey | ||
Adds ~\.ssh\id_rsa to the SSH agent. | ||
.EXAMPLE | ||
PS C:\> Add-SshKey ~\.ssh\mykey, ~\.ssh\myotherkey | ||
Adds ~\.ssh\mykey and ~\.ssh\myotherkey to the SSH agent. | ||
.INPUTS | ||
None. | ||
You cannot pipe input to this cmdlet. | ||
#> | ||
function Add-SshKey([switch]$Quiet) { | ||
if ($env:GIT_SSH -imatch 'plink') { | ||
$pageant = Get-Command pageant -Erroraction SilentlyContinue | Select-Object -First 1 -ExpandProperty Name | ||
$pageant = if ($pageant) { $pageant } else { Find-Pageant } | ||
if (!$pageant) { | ||
if (!$Quiet) { | ||
Write-Warning 'Could not find Pageant' | ||
} | ||
return | ||
} | ||
|
||
if ($args.Count -eq 0) { | ||
$keyPath = Join-Path $Env:HOME .ssh | ||
$keys = Get-ChildItem $keyPath/*.ppk -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName | ||
if ($keys) { | ||
& $pageant $keys | ||
} | ||
} | ||
else { | ||
foreach ($value in $args) { | ||
& $pageant $value | ||
} | ||
} | ||
} | ||
else { | ||
$sshAdd = Get-Command ssh-add -TotalCount 1 -ErrorAction SilentlyContinue | ||
$sshAdd = if ($sshAdd) { $sshAdd } else { Find-Ssh('ssh-add') } | ||
if (!$sshAdd) { | ||
if (!$Quiet) { | ||
Write-Warning 'Could not find ssh-add' | ||
} | ||
return | ||
} | ||
|
||
if ($args.Count -eq 0) { | ||
& $sshAdd | ||
} | ||
else { | ||
foreach ($value in $args) { | ||
& $sshAdd $value | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.