diff options
| author | Alexander Karatarakis <alex@karatarakis.com> | 2017-12-04 16:33:43 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-12-04 16:33:43 -0800 |
| commit | 3f053c15f50ad67da4bb3c04f718f6d49e203e5e (patch) | |
| tree | 4f509e5dd99bed46ce7fcf7547ea8bf375f8d8fc /scripts | |
| parent | e30cabce354a4e0cbf06e5a4708b96fbb98f0dda (diff) | |
| parent | 1a9a14b3ce456289c2a4523079e0104dc17a9758 (diff) | |
| download | vcpkg-3f053c15f50ad67da4bb3c04f718f6d49e203e5e.tar.gz vcpkg-3f053c15f50ad67da4bb3c04f718f6d49e203e5e.zip | |
Merge pull request #2260 from Microsoft/PowershellTabCompletion
[posh-vcpkg] Add `vcpkg integrate powershell` for enabling tab-completion
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/addPoshVcpkgToPowershellProfile.ps1 | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/addPoshVcpkgToPowershellProfile.ps1 b/scripts/addPoshVcpkgToPowershellProfile.ps1 new file mode 100644 index 000000000..92a7573e4 --- /dev/null +++ b/scripts/addPoshVcpkgToPowershellProfile.ps1 @@ -0,0 +1,55 @@ +[CmdletBinding()] +param() + +function findExistingImportModuleDirectives([Parameter(Mandatory=$true)][string]$path) +{ + if (!(Test-Path $path)) + { + return $false + } + + $fileContents = Get-Content $path + return $fileContents -match 'Import-Module.+?(?=posh-vcpkg)' +} + +$scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition +. "$scriptsDir\VcpkgPowershellUtils.ps1" + +$profileEntry = "Import-Module '$scriptsDir\posh-vcpkg'" +$profilePath = $PROFILE # Implicit powershell variable +if (!(Test-Path $profilePath)) +{ + $profileDir = Split-Path $profilePath -Parent + vcpkgCreateDirectoryIfNotExists $profileDir +} + +Write-Host "`nAdding the following line to ${profilePath}:" +Write-Host " $profileEntry" + +# @() Needed to force Array in PowerShell 2.0 +[Array]$existingImports = @(findExistingImportModuleDirectives $profilePath) +if ($existingImports.Count -gt 0) +{ + $existingImportsOut = $existingImports -join "`n " + Write-Host "`nposh-vcpkg is already imported to your PowerShell profile. The following entries were found:" + Write-Host " $existingImportsOut" + Write-Host "`nPlease make sure you have started a new Powershell window for the changes to take effect." + return +} + +# Posh-git does the following check, so we should too. +# https://github.com/dahlbyk/posh-git/blob/master/src/Utils.ps1 +# If the profile script exists and is signed, then we should not modify it +if (Test-Path $profilePath) +{ + $sig = Get-AuthenticodeSignature $profilePath + if ($null -ne $sig.SignerCertificate) + { + Write-Warning "Skipping add of posh-vcpkg import to profile; '$profilePath' appears to be signed." + Write-Warning "Please manually add the line '$profileEntry' to your profile and resign it." + return + } +} + +Add-Content $profilePath -Value "`n$profileEntry" -Encoding UTF8 +Write-Host "`nSuccessfully added posh-vcpkg to your PowerShell profile. Please start a new Powershell window for the changes to take effect." |
