From bcf1a4defb341fa1e8efdfaebe594070b370a0ad Mon Sep 17 00:00:00 2001 From: Albert Weinert Date: Mon, 25 Mar 2013 22:52:13 +0100 Subject: [PATCH] Store SSH environment info in %TEMP%\.ssh [EnvironmentVariableTarget]::User is painfully slow, because it notifies other processes of the changed value. Closes #88 --- GitUtils.ps1 | 22 +++++++++++++++++++++- posh-git.psm1 | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/GitUtils.ps1 b/GitUtils.ps1 index ebe5c7f8e..b155dbdd0 100644 --- a/GitUtils.ps1 +++ b/GitUtils.ps1 @@ -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 diff --git a/posh-git.psm1 b/posh-git.psm1 index 038667395..b397a1300 100644 --- a/posh-git.psm1 +++ b/posh-git.psm1 @@ -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 @( '??') `