|
param( |
|
# Parameter help description |
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$GistID = "notheotherben/77ccb460948afd826365e85d226509a7", |
|
|
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$ColourScheme = "Afterglow", |
|
|
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$TempFolder = "${env:Temp}/powershell_setup/" |
|
) |
|
|
|
function Download-GitHubRelease { |
|
param( |
|
[Parameter(Mandatory = $true)] |
|
[string] |
|
$Repo, |
|
|
|
[Parameter(Mandatory = $true)] |
|
[string] |
|
$File, |
|
|
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$ReleaseTag = "latest" |
|
) |
|
|
|
if ($ReleaseTag -eq "latest") { |
|
$ReleaseTag = (Invoke-WebRequest "https://api.github.com/repos/${Repo}/releases" | ConvertFrom-Json)[0].tag_name |
|
} |
|
|
|
Invoke-WebRequest -Uri "https://github.com/${Repo}/releases/download/${ReleaseTag}/${File}" -OutFile $File |
|
} |
|
|
|
function Install-GitTool { |
|
param ( |
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$Version = "latest" |
|
) |
|
|
|
if (-not (Get-Module -ListAvailable -Name PowerShellGet)) { |
|
# Install the PowerShellGet module for the current user |
|
Install-Module Git-Tool -Scope CurrentUser -Force -AllowClobber |
|
} |
|
|
|
if ($Version -eq "latest") { |
|
$Version = (PowerShellGet\Find-Module -AllVersions Git-Tool | Select-Object -First 1).Version |
|
Write-Host "Latest version of Git-Tool: $Version" |
|
} |
|
|
|
Write-Host "Installing Git-Tool@$Version" |
|
PowerShellGet\Install-Module Git-Tool -Scope CurrentUser -Force -RequiredVersion $Version |
|
} |
|
|
|
function Install-PoshGit { |
|
param ( |
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$Version = "latest" |
|
) |
|
|
|
if (-not (Get-Module -ListAvailable -Name PowerShellGet)) { |
|
# Install the PowerShellGet module for the current user |
|
Install-Module PowerShellGet -Scope CurrentUser -Force -AllowClobber |
|
} |
|
|
|
if ($Version -eq "latest") { |
|
$Version = (PowerShellGet\Find-Module -AllVersions -AllowPrerelease posh-git | Select-Object -First 1).Version |
|
Write-Host "Latest version of PoshGit: $Version" |
|
} |
|
|
|
Write-Host "Installing Posh-Git@$Version" |
|
PowerShellGet\Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force -RequiredVersion $Version |
|
} |
|
|
|
function Install-ColorTool { |
|
param( |
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$Scheme = "Afterglow", |
|
|
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$TempFolder = "${env:Temp}/powershell_setup/" |
|
) |
|
|
|
Push-Location $TempFolder |
|
try { |
|
Write-Host "Downloading ColorTool and $Scheme colour scheme" |
|
|
|
Download-GitHubRelease -Repo "Microsoft/console" -File "ColorTool.zip" |
|
|
|
Expand-Archive ColorTool.zip -DestinationPath . |
|
Invoke-WebRequest -Uri "https://github.com/mbadolato/iTerm2-Color-Schemes/raw/master/schemes/${Scheme}.itermcolors" -OutFile "schemes\${Scheme}.itermcolors" |
|
} finally { |
|
Pop-Location |
|
} |
|
} |
|
|
|
function Install-HackFont { |
|
param( |
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$TempFolder = "${env:Temp}/powershell_setup/" |
|
) |
|
|
|
Push-Location $TempFolder |
|
try { |
|
Write-Host "Downloading Hack font" |
|
Download-GitHubRelease -Repo "source-foundry/Hack-windows-installer" -File "HackFontsWindowsInstaller.exe" |
|
|
|
Start-Process -Wait .\HackFontsWindowsInstaller.exe |
|
} finally { |
|
Pop-Location |
|
} |
|
} |
|
|
|
function Configure-ColorTool { |
|
param( |
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$Scheme = "Afterglow", |
|
|
|
[Parameter(Mandatory = $false)] |
|
[string] |
|
$TempFolder = "${env:Temp}/powershell_setup/" |
|
) |
|
|
|
Push-Location $TempFolder |
|
|
|
try { |
|
Write-Host "Configuring console to use $Scheme colour scheme" |
|
Start-Process -NoNewWindow -Wait .\ColorTool.exe -ArgumentList ("-b", "$Scheme") |
|
} finally { |
|
Pop-Location |
|
} |
|
} |
|
|
|
function Install-Profile { |
|
Invoke-WebRequest -Uri "https://gist.githubusercontent.com/${GistID}/raw/profile.ps1" | Set-Content -Path $profile.CurrentUserAllHosts |
|
} |
|
|
|
try { |
|
New-Item -Type Directory -Path $TempFolder | Out-Null |
|
|
|
Install-PoshGit |
|
Install-GitTool |
|
Install-ColorTool -Scheme $ColourScheme -TempFolder $TempFolder |
|
Configure-ColorTool -Scheme $ColourScheme -TempFolder $TempFolder |
|
Install-HackFont |
|
Install-Profile |
|
|
|
Write-Host "Please open your terminal's options dialog and click OK to save changes" |
|
} |
|
finally { |
|
Remove-Item -Path $TempFolder -Recurse -Force | Out-Null |
|
} |