Allow creation of additional themes
This commit is contained in:
parent
9cc284e086
commit
abb686c564
1 changed files with 26 additions and 16 deletions
|
@ -27,31 +27,41 @@ Start-SoftwareInstaller @PSBoundParameters `
|
||||||
|
|
||||||
$theme = Get-UserConfig "oh-my-posh.theme";
|
$theme = Get-UserConfig "oh-my-posh.theme";
|
||||||
|
|
||||||
|
function New-Theme {
|
||||||
|
param($info)
|
||||||
|
$root = "$($IsWindows ? $env:AppData : "~/.config")/oh-my-posh";
|
||||||
|
$path = Join-Path $root "$($info.name).omp.json";
|
||||||
|
$null = New-Item -Force -ItemType Directory $root;
|
||||||
|
|
||||||
|
Set-Content $path (
|
||||||
|
& {
|
||||||
|
if ($IsWindows) {
|
||||||
|
wsl cat $info.source;
|
||||||
|
} else {
|
||||||
|
cat $info.source;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($additionalTheme in (Get-UserConfig "oh-my-posh.additionalThemes")) {
|
||||||
|
Write-Host "creating theme $additionalTheme"
|
||||||
|
$null = New-Theme $additionalTheme;
|
||||||
|
}
|
||||||
|
|
||||||
if ($theme) {
|
if ($theme) {
|
||||||
$varName = "POSH_THEME";
|
$varName = "POSH_THEME";
|
||||||
|
|
||||||
if ($theme -isnot [string]) {
|
if ($theme -isnot [string]) {
|
||||||
$root = "$($IsWindows ? $env:AppData : "~/.config")/oh-my-posh";
|
$theme = [string](New-Theme $theme);
|
||||||
$path = Join-Path $root "$($theme.name).omp.json";
|
|
||||||
$null = New-Item -Force -ItemType Directory $root;
|
|
||||||
|
|
||||||
Set-Content $path (
|
|
||||||
& {
|
|
||||||
if ($IsWindows) {
|
|
||||||
wsl cat $theme.source
|
|
||||||
} else {
|
|
||||||
cat $theme.source
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$theme = [string] $path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($IsWindows) {
|
if ($IsWindows) {
|
||||||
[System.Environment]::SetEnvironmentVariable($varName, "%AppData%/$([System.IO.Path]::GetRelativePath($env:AppData, $path))", "User");
|
[System.Environment]::SetEnvironmentVariable($varName, "%AppData%/$([System.IO.Path]::GetRelativePath($env:AppData, $theme))", "User");
|
||||||
} else {
|
} else {
|
||||||
. "$PSScriptRoot/../aliae/Manage.ps1";
|
. "$PSScriptRoot/../aliae/Manage.ps1";
|
||||||
Add-EnvironmentVariable -User $Arguments.Name $varName ($path).Replace("~", "{{ .Home }}");
|
Add-EnvironmentVariable -User $Arguments.Name $varName ($theme).Replace("~", "{{ .Home }}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue