Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save d1820/a3217bcca482f1c05c11abfd777e1ccc to your computer and use it in GitHub Desktop.
Save d1820/a3217bcca482f1c05c11abfd777e1ccc to your computer and use it in GitHub Desktop.
Install Terminal Icons and POSH for Powershell
param(
[string]$theme = "quick-term.omp.json",
[string]$font = "Meslo"
)
$moduleName = "Terminal-Icons"
$poshName = "JanDeDobbeleer.OhMyPosh"
Write-Host "Installing Terminal Icons..." -ForegroundColor Blue
Install-Module -Name $moduleName -Repository PSGallery
Write-Host "Installing Posh..." -ForegroundColor Blue
winget install $poshName -s winget
if (-not (Test-Path $PROFILE)) {
New-Item -Path $PROFILE -ItemType File -Force
Write-Output "PowerShell profile created."
}
Write-Host "Accessing Profile $PROFILE" -ForegroundColor Blue
$newLine = '`nImport-Module -Name Terminal-Icons`n'
# Check if the line already exists in the profile
if (Select-String -Path $PROFILE -Pattern 'Import-Module -Name Terminal-Icons') {
}
else {
# If the line does not exist, append the new line to the profile
Add-Content -Path $PROFILE -Value $newLine
Write-Host "Added Terminal Icons to PowerShell profile." -ForegroundColor Blue
}
# Define the content to be added or replaced in the profile
$newLine = "`noh-my-posh init pwsh --config ""$env:POSH_THEMES_PATH\$($theme)"" | Invoke-Expression`n"
# Check if the line already exists in the profile
if (Select-String -Path $PROFILE -Pattern 'oh-my-posh init pwsh') {
# If the line exists, replace the entire line with the new line
(Get-Content $PROFILE) | ForEach-Object {
if ($_ -like '*oh-my-posh init pwsh*') {
$_ -replace '.*oh-my-posh init pwsh.*', $newLine
}
else {
$_
}
} | Set-Content $PROFILE
Write-Host "Updated Posh to Theme $theme in PowerShell profile." -ForegroundColor Blue
}
else {
# If the line does not exist, append the new line to the profile
Add-Content -Path $PROFILE -Value $newLine
Write-Host "Added Posh Theme $theme to PowerShell profile." -ForegroundColor Blue
}
Write-Host "Reloading Profile..." -ForegroundColor Blue
. $PROFILE
Write-Host "Installing Font..." -ForegroundColor Blue
$installedFonts = Get-ChildItem -Path "C:\Windows\Fonts" | Where-Object { $_.Name -like "$font*" }
if ($installedFonts) {
Write-Host "Font '$font' is already installed:"
}
else {
& "$env:USERPROFILE\AppData\Local\Programs\oh-my-posh\bin\oh-my-posh.exe" font install $font
}
Write-Host "Installation Complete. Reload Terminal" -ForegroundColor Green
# Adding Posh to profile (windows powershell)
# C:\Users\USERNAME\Documents\WindowsPowerShell
# Adding Posh to profile (powershell 7)
# C:\Users\USERNAME\Documents\Powershell
Import-Module -Name Terminal-Icons
oh-my-posh init pwsh --config "C:\Users\USERNAME\AppData\Local\Programs\oh-my-posh\themes\quick-term.omp.json" | Invoke-Expression
# Adding Posh to profile (vscode powershell)
# C:\Users\USERNAME\Documents\WindowsPowerShell
# Adding Posh to profile (powershell 7)
# C:\Users\USERNAME\Documents\Powershell
Import-Module -Name Terminal-Icons
oh-my-posh init pwsh --config "C:\Users\USERNAME\AppData\Local\Programs\oh-my-posh\themes\quick-term.omp.json" | Invoke-Expression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment