Last active
October 31, 2024 02:16
-
-
Save ril3y/98b3a6495d8d5cbc256c5d8020754132 to your computer and use it in GitHub Desktop.
installer.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: Check if Python is installed | |
function Ensure-Python { | |
if (-not (Get-Command python -ErrorAction SilentlyContinue)) { | |
Write-Host "Python not found. Installing Python..." -ForegroundColor Yellow | |
$pythonInstaller = "$env:TEMP\python-installer.exe" | |
Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.x.x/python-3.x.x-amd64.exe" -OutFile $pythonInstaller | |
Start-Process -FilePath $pythonInstaller -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait | |
Remove-Item $pythonInstaller | |
} else { | |
Write-Host "Python is already installed." -ForegroundColor Green | |
} | |
} | |
# Step 2: Ensure virtualenv is set up | |
function Ensure-VirtualEnv { | |
if (-not (Test-Path "$env:USERPROFILE\myvenv")) { | |
Write-Host "Virtual environment not found. Setting up virtual environment..." -ForegroundColor Yellow | |
python -m venv "$env:USERPROFILE\myvenv" | |
} else { | |
Write-Host "Virtual environment already exists." -ForegroundColor Green | |
} | |
if (-not $env:VIRTUAL_ENV) { | |
Write-Host "Activating virtual environment..." -ForegroundColor Yellow | |
& "$env:USERPROFILE\myvenv\Scripts\Activate.ps1" | |
} | |
} | |
# Step 3: Ensure Oh-My-Posh is installed | |
function Ensure-OhMyPosh { | |
if (-not (Get-Command oh-my-posh -ErrorAction SilentlyContinue)) { | |
Write-Host "Oh-My-Posh not found. Installing Oh-My-Posh..." -ForegroundColor Yellow | |
winget install JanDeDobbeleer.OhMyPosh -s winget | |
# Force a refresh of the PATH environment variable so the command is recognized | |
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::Machine) | |
} else { | |
Write-Host "Oh-My-Posh is already installed." -ForegroundColor Green | |
} | |
} | |
# Step 4: Ensure Nerd Fonts are installed | |
function Ensure-NerdFonts { | |
$fontFolder = "$env:USERPROFILE\Fonts" | |
if (-not (Test-Path $fontFolder)) { | |
New-Item -ItemType Directory -Path $fontFolder | |
} | |
if (-not (Test-Path "$fontFolder\Hack Nerd Font Complete.ttf")) { | |
Write-Host "Installing Nerd Fonts..." -ForegroundColor Yellow | |
$fontUrl = "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Hack.zip" | |
$fontZip = "$env:TEMP\Hack.zip" | |
$fontExtractPath = "$env:TEMP\Hack" | |
Invoke-WebRequest -Uri $fontUrl -OutFile $fontZip | |
Expand-Archive -Path $fontZip -DestinationPath $fontExtractPath | |
Copy-Item "$fontExtractPath\*.ttf" -Destination $fontFolder | |
Remove-Item $fontZip, $fontExtractPath -Recurse | |
Write-Host "Nerd Fonts installed. Please set this font in your terminal." -ForegroundColor Green | |
} else { | |
Write-Host "Nerd Fonts already installed." -ForegroundColor Green | |
} | |
} | |
# Step 5: Ensure Oh-My-Posh Powerline theme is set | |
function Ensure-OhMyPoshTheme { | |
$themePath = "$env:USERPROFILE\oh-my-posh-themes" | |
if (-not (Test-Path $themePath)) { | |
New-Item -ItemType Directory -Path $themePath | |
Invoke-WebRequest -Uri "https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip" -OutFile "$themePath\themes.zip" | |
Expand-Archive -Path "$themePath\themes.zip" -DestinationPath $themePath | |
Remove-Item "$themePath\themes.zip" | |
} | |
oh-my-posh init pwsh --config "$themePath\powerline.omp.json" | Invoke-Expression | |
} | |
# Ensure all components are installed | |
Ensure-Python | |
Ensure-VirtualEnv | |
Ensure-OhMyPosh | |
Ensure-NerdFonts | |
Ensure-OhMyPoshTheme |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment