Skip to content

Instantly share code, notes, and snippets.

@Jawabiscuit
Last active December 28, 2021 03:55
Show Gist options
  • Save Jawabiscuit/99ce1fc7a7047d39399d5336ff2e1003 to your computer and use it in GitHub Desktop.
Save Jawabiscuit/99ce1fc7a7047d39399d5336ff2e1003 to your computer and use it in GitHub Desktop.
Setup Powershell console with dracula theme.
###################################################################################################
### PowerShell console with dracula theme ###
### - Run this script ###
### - Double-check "Windows PowerShell.lnk" and "Windows PowerShell (x86).lnk" get overwritten ###
### Prerequisites ###
### 1. PSReadLine 2.0 or later, Windows comes with 1.0 installed as of 2021/12 ###
### 2. posh-git for git integration ###
### More Details ###
### - https://github.com/dracula/powershell/blob/master/theme/dracula-prompt-configuration.ps1 ###
### - https://github.com/dracula/powershell#user-content-profile-explanation ###
### - https://draculatheme.com/powershell ###
###################################################################################################
Write-Host "[setup-dracula] Configuring console..." -ForegroundColor "Yellow"
Set-ExecutionPolicy Bypass -Scope Process -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# Config that gets written to user $profile
$config = @"
# Dracula readline configuration. Requires version 2.0, if you have 1.2 convert to `Set-PSReadlineOption -TokenType`
Set-PSReadlineOption -Color @{
"Command" = [ConsoleColor]::Green
"Parameter" = [ConsoleColor]::Gray
"Operator" = [ConsoleColor]::Magenta
"Variable" = [ConsoleColor]::White
"String" = [ConsoleColor]::Yellow
"Number" = [ConsoleColor]::Blue
"Type" = [ConsoleColor]::Cyan
"Comment" = [ConsoleColor]::DarkCyan
}
# Dracula Prompt Configuration
Import-Module posh-git
$GitPromptSettings.DefaultPromptPrefix.Text = "$([char]0x2192) " # arrow unicode symbol
$GitPromptSettings.DefaultPromptPrefix.ForegroundColor = [ConsoleColor]::Green
$GitPromptSettings.DefaultPromptPath.ForegroundColor =[ConsoleColor]::Cyan
$GitPromptSettings.DefaultPromptSuffix.Text = "$([char]0x203A) " # chevron unicode symbol
$GitPromptSettings.DefaultPromptSuffix.ForegroundColor = [ConsoleColor]::Magenta
# Dracula Git Status Configuration
$GitPromptSettings.BeforeStatus.ForegroundColor = [ConsoleColor]::Blue
$GitPromptSettings.BranchColor.ForegroundColor = [ConsoleColor]::Blue
$GitPromptSettings.AfterStatus.ForegroundColor = [ConsoleColor]::Blue
"@
# Install dependencies
if (Find-Module PowerShellGet)
{
# Silence this warning
# WARNING: Version '2.2.5' of module 'PowerShellGet' is already installed
if ((Get-Module -Name PowerShellGet).Version.Major -ne "2")
{
Write-Host "[setup-dracula] Installing PSReadLine..." -ForegroundColor "Green"
Install-Module -Name PowerShellGet -RequiredVersion 2.2.5
}
}
else
{
# Fix update issue: https://github.com/PowerShell/PowerShellGetv2/issues/599
Install-Module -Name PowerShellGet -RequiredVersion 2.2.5
}
# Upgrade/Install PSReadline dependency
if ($(Get-Module -ListAvailable PSReadLine).Count -eq 0)
{
Write-Host "[setup-dracula] Installing PSReadLine..." -ForegroundColor "Green"
Install-Module -Name PSReadLine -Force
}
# Upgrade to version 2 or later
elseif (!(Get-Module PSReadLine).Version.Major -gt 1)
{
Write-Host "[setup-dracula] Updating PSReadLine..." -ForegroundColor "Green"
Install-Module -Name PSReadLine -AllowClobber -Force
}
# Install posh-git
# Cannot pipe Install-Module posh-git
if (!(Find-Module posh-git))
{
Install-Module -Name posh-git -AllowPrerelease -Force
}
# Download and unzip ColorTool
$url = "https://raw.githubusercontent.com/waf/dracula-cmd/master/dist/ColorTool.zip"
$archiveName = "ColorTool.zip"
$extractDir = Join-Path $env:temp "dracula_setup"
$archivePath = Join-Path $extractDir $archiveName
if (!(Test-Path $extractDir)) {
New-Item $extractDir -ItemType Directory
}
else
{
Write-Warning "[setup-dracula] Directory exists: $extractDir"
Write-Warning "Remove before running setup again"
}
if (!(Test-Path $archivePath)) {
Write-Host "[setup-dracula] Downloading..." -ForegroundColor "Green"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri "$url" -OutFile "$archivePath"
if (Test-Path -Path "$archivePath" -PathType Leaf) {
$zipfile = Get-Item "$archivePath"
Write-Host "[setup-dracula] Downloaded successfully" -ForegroundColor "Green"
Write-Host "[setup-dracula] Extracting $archivePath to ${extractDir}..." -ForegroundColor "Green"
Expand-Archive $archivePath -DestinationPath $zipfile.DirectoryName
$installScript = Join-Path $zipfile.DirectoryName $zipfile.Basename "install.cmd"
if (Test-Path -Path $installScript -PathType Leaf) {
Write-Host ("[setup-dracula] Executing {0}..." -f $installScript.Name) -ForegroundColor "Green"
Invoke-Item $installScript
$config >> $profile
} else {
Write-Error "[setup-dracula] $zipfile was not found!"
}
} else {
Write-Error "[setup-dracula] Download failed"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment