Created
February 8, 2024 05:01
-
-
Save gethari/023b5496b11c63d7d3a325fb3e0242fd to your computer and use it in GitHub Desktop.
Random oh-my-posh theme on every new terminal
This file contains hidden or 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
function Get-RandomPoshThemeFile { | |
# Get the Posh-Themes directory path from the environment variable. | |
$poshThemesPath = $env:POSH_THEMES_PATH | |
# Check if the Posh-Themes directory exists. | |
if (!$poshThemesPath -or !(Test-Path $poshThemesPath)) { | |
throw "The POSH_THEMES_PATH environment variable is not set or the directory does not exist." | |
} | |
# Get a list of all theme files with the .omp.json extension. | |
$themeFiles = Get-ChildItem -Path $poshThemesPath -Filter "*.omp.json" | |
# Check if there are any theme files. | |
if ($themeFiles.Count -eq 0) { | |
throw "No theme files found in Posh-Themes path." | |
} | |
# Select a random theme file. | |
$randomThemeFile = $themeFiles | Get-Random | |
Write-Host("Using theme: $randomThemeFile") | |
return $randomThemeFile | |
} | |
$theme = Get-RandomPoshThemeFile | |
oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\$theme" | Invoke-Expression | |
Import-Module 'C:\Hari\posh-git\src\posh-git.psd1' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment