Skip to content

Instantly share code, notes, and snippets.

@notheotherben
Last active December 28, 2022 14:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notheotherben/77ccb460948afd826365e85d226509a7 to your computer and use it in GitHub Desktop.
Save notheotherben/77ccb460948afd826365e85d226509a7 to your computer and use it in GitHub Desktop.
PowerShell Configuration

PowerShell Configuration

To setup your PowerShell to match mine, simply run the following commands:

# You may need to run this in an administrative PowerShell instance
Set-ExecutionPolicy Unrestricted

$SetupScript = Invoke-WebRequest https://gist.githubusercontent.com/notheotherben/77ccb460948afd826365e85d226509a7/raw/setup.ps1
$ScriptBlock = [ScriptBlock]::Create($SetupScript.Content)
Invoke-Command -ScriptBlock $ScriptBlock

Features

  • Installs Hack on your system (a really nice monospace font-face)
  • Installs PoshGit to give you useful information about Git repos from your PowerShell.
  • Installs the Afterglow colour scheme in your terminal.
  • Configures your prompt to look a bit cleaner especially when dealing with long paths.
Import-Module posh-git
Import-Module Git-Tool
$GitPromptSettings.DefaultPromptPath.ForegroundColor = 0x6a6656
$GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n'
$GitPromptSettings.DefaultPromptSuffix.Text = '$(" " * $nestedPromptLevel)$([char]0x03BB) '
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment