2024-08-23 21:53:48 +00:00
|
|
|
. "$PSScriptRoot/../aliae/Manage.ps1";
|
2024-10-13 13:35:24 +00:00
|
|
|
. "$PSScriptRoot/../powershell/Profile.ps1";
|
2024-11-01 12:12:16 +00:00
|
|
|
. "$PSScriptRoot/../../../lib/Software.ps1";
|
2024-08-07 21:22:04 +00:00
|
|
|
. "$PSScriptRoot/../../Types/InstallerAction.ps1";
|
|
|
|
|
2024-09-30 03:00:20 +00:00
|
|
|
Start-SoftwareInstaller @args `
|
2024-08-07 21:22:04 +00:00
|
|
|
-Configurator {
|
2024-09-23 00:10:42 +00:00
|
|
|
param([string] $Name)
|
|
|
|
|
2024-08-07 21:22:04 +00:00
|
|
|
Add-PowerShellProfileStatement `
|
|
|
|
-System `
|
2024-09-23 00:10:42 +00:00
|
|
|
-Category "$Name" `
|
2024-08-07 21:22:04 +00:00
|
|
|
-Script (
|
|
|
|
@(
|
|
|
|
"# Oh My Posh!",
|
|
|
|
(Get-ScriptInitializer "oh-my-posh init pwsh"),
|
|
|
|
(Get-ScriptInitializer "oh-my-posh completion powershell")
|
2024-10-06 19:25:34 +00:00
|
|
|
) -join [System.Environment]::NewLine);
|
2024-08-23 21:53:48 +00:00
|
|
|
} `
|
|
|
|
-UserConfigurator {
|
|
|
|
param(
|
|
|
|
[hashtable] $Arguments
|
|
|
|
)
|
|
|
|
|
2024-09-27 23:24:28 +00:00
|
|
|
$user = $Arguments.Name;
|
2024-10-13 17:52:28 +00:00
|
|
|
$theme = Get-UserConfig -UserName "$user" "programs.oh-my-posh.theme";
|
2024-08-23 21:53:48 +00:00
|
|
|
|
2024-09-22 22:10:05 +00:00
|
|
|
function New-Theme {
|
|
|
|
param($info)
|
2024-09-27 23:24:28 +00:00
|
|
|
|
|
|
|
$root = "$(& {
|
|
|
|
if ($IsWindows) {
|
|
|
|
sudo -u "$user" pwsh -c 'Write-Host $env:AppData';
|
|
|
|
} else {
|
2024-10-06 19:25:34 +00:00
|
|
|
sudo -u "$user" bash -c 'realpath ~/.config';
|
2024-09-27 23:24:28 +00:00
|
|
|
}
|
|
|
|
})/oh-my-posh";
|
|
|
|
|
2024-09-22 22:10:05 +00:00
|
|
|
$path = Join-Path $root "$($info.name).omp.json";
|
2024-09-27 23:24:28 +00:00
|
|
|
$null = sudo -u "$user" pwsh -c New-Item -Force -ItemType Directory $root;
|
2024-09-22 22:10:05 +00:00
|
|
|
|
2024-09-27 23:24:28 +00:00
|
|
|
sudo -u "$user" pwsh -CommandWithArgs 'Set-Content $args[0] -Value $args[1]' $path ([string](
|
2024-09-22 22:10:05 +00:00
|
|
|
& {
|
|
|
|
if ($IsWindows) {
|
2024-09-28 01:41:00 +00:00
|
|
|
wsl cat $info.source | Out-String;
|
2024-10-06 19:25:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2024-09-27 23:24:28 +00:00
|
|
|
Get-Content -Raw $info.source;
|
2024-09-22 22:10:05 +00:00
|
|
|
}
|
2024-09-27 23:24:28 +00:00
|
|
|
}));
|
2024-09-22 22:10:05 +00:00
|
|
|
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
|
2024-10-13 17:52:28 +00:00
|
|
|
foreach ($additionalTheme in (Get-UserConfig -UserName "$user" "programs.oh-my-posh.additionalThemes")) {
|
2024-10-06 19:25:34 +00:00
|
|
|
Write-Host "creating theme $additionalTheme";
|
2024-09-22 22:10:05 +00:00
|
|
|
$null = New-Theme $additionalTheme;
|
|
|
|
}
|
|
|
|
|
2024-08-23 21:53:48 +00:00
|
|
|
if ($theme) {
|
|
|
|
$varName = "POSH_THEME";
|
|
|
|
|
|
|
|
if ($theme -isnot [string]) {
|
2024-09-22 22:10:05 +00:00
|
|
|
$theme = [string](New-Theme $theme);
|
2024-08-23 21:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($IsWindows) {
|
2024-10-11 23:52:34 +00:00
|
|
|
[System.Environment]::SetEnvironmentVariable($varName, $theme, "User");
|
2024-10-06 19:25:34 +00:00
|
|
|
}
|
|
|
|
else {
|
2024-08-23 21:53:48 +00:00
|
|
|
. "$PSScriptRoot/../aliae/Manage.ps1";
|
2024-09-27 23:24:28 +00:00
|
|
|
$value = $theme;
|
|
|
|
$relativePath = sudo -u "$user" fish -c 'realpath --relative-base ~ $argv' $theme;
|
|
|
|
|
|
|
|
if ($relativePath -ne $theme) {
|
|
|
|
$value = Join-Path "{{ .Home }}" $relativePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
Add-EnvironmentVariable -User $Arguments.Name $varName $value;
|
2024-08-23 21:53:48 +00:00
|
|
|
}
|
|
|
|
}
|
2024-08-07 21:22:04 +00:00
|
|
|
};
|