Skip to content

Commit

Permalink
Store SSH environment info in %TEMP%\.ssh
Browse files Browse the repository at this point in the history
[EnvironmentVariableTarget]::User is painfully slow, because it notifies other processes of the changed value.

Closes #88
  • Loading branch information
DerAlbertCom authored and dahlbyk committed Mar 30, 2013
1 parent 7eed923 commit bcf1a4d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 21 additions & 1 deletion GitUtils.ps1
Expand Up @@ -200,7 +200,27 @@ function Get-AliasPattern($exe) {

function setenv($key, $value) {
[void][Environment]::SetEnvironmentVariable($key, $value, [EnvironmentVariableTarget]::Process)
[void][Environment]::SetEnvironmentVariable($key, $value, [EnvironmentVariableTarget]::User)
Set-TempEnv $key $value
}

function Get-TempEnv($key) {
$path = Join-Path ($Env:TEMP) ".ssh\$key.env"
if (Test-Path $path) {
$value = Get-Content $path
[void][Environment]::SetEnvironmentVariable($key, $value, [EnvironmentVariableTarget]::Process)
}
}

function Set-TempEnv($key, $value) {
$path = Join-Path ($Env:TEMP) ".ssh\$key.env"
if ($value -eq $null) {
if (Test-Path $path) {
Remove-Item $path
}
} else {
New-Item $path -Force -ItemType File > $null
$value > $path
}
}

# Retrieve the current SSH agent PID (or zero). Can be used to determine if there
Expand Down
3 changes: 3 additions & 0 deletions posh-git.psm1
Expand Up @@ -13,6 +13,9 @@ Pop-Location
if (!$Env:HOME) { $Env:HOME = "$Env:HOMEDRIVE$Env:HOMEPATH" }
if (!$Env:HOME) { $Env:HOME = "$Env:USERPROFILE" }

Get-TempEnv 'SSH_AGENT_PID'
Get-TempEnv 'SSH_AUTH_SOCK'

Export-ModuleMember `
-Alias @(
'??') `
Expand Down

1 comment on commit bcf1a4d

@khengyun
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will try this. thanks you every much <3

Please sign in to comment.