feat(Posh-VsVars): version 0.0.1

- Includes new set of PowerShellHelpers to find
   standard module directory
This commit is contained in:
Iristyle
2013-05-09 11:29:14 -04:00
parent a27a198161
commit c459306a94
4 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
function Get-ModuleDirectory
{
[CmdletBinding()]
param()
# find the first default module path we can safely write to
$defaultModulePath = $Env:PSModulePath -split ';' |
? {
Write-Verbose "Checking path $_ for write-ability"
try {
if (!(Test-Path $_)) { New-Item -Path $_ -Type Directory }
$testFile = Join-Path $_ 'write-test.tmp'
'' | Out-File -FilePath $testFile
Remove-Item -Path $testFile
return $true
}
catch { return $false }
} |
Select -First 1
if ($defaultModulePath) { return $defaultModulePath }
# no defaults were acceptable, so try Choc paths
$tools = Join-Path $Env:SystemDrive 'tools'
if ($Env:Chocolatey_Bin_Root)
{
$tools = Join-Path $Env:SystemDrive $Env:Chocolatey_Bin_Root
}
if (!(Test-Path $tools))
{
New-Item -Path $tools -Type Directory | Out-Null
}
return $tools
}