Fix aliae and omp configuration for Linux

This commit is contained in:
Manuel Thalmann 2024-09-28 01:24:28 +02:00
parent 5965918bf6
commit f5a1b0cb86
2 changed files with 31 additions and 12 deletions

View file

@ -27,27 +27,36 @@ Start-SoftwareInstaller @PSBoundParameters `
[hashtable] $Arguments [hashtable] $Arguments
) )
$theme = Get-UserConfig "oh-my-posh.theme"; $user = $Arguments.Name;
$theme = Get-UserConfig -UserName "$user" "oh-my-posh.theme";
function New-Theme { function New-Theme {
param($info) 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 ( $root = "$(& {
if ($IsWindows) {
sudo -u "$user" pwsh -c 'Write-Host $env:AppData';
} else {
sudo -u "$user" bash -c 'realpath ~/.config'
}
})/oh-my-posh";
$path = Join-Path $root "$($info.name).omp.json";
$null = sudo -u "$user" pwsh -c New-Item -Force -ItemType Directory $root;
sudo -u "$user" pwsh -CommandWithArgs 'Set-Content $args[0] -Value $args[1]' $path ([string](
& { & {
if ($IsWindows) { if ($IsWindows) {
wsl cat $info.source; wsl cat $info.source;
} else { } else {
cat $info.source; Get-Content -Raw $info.source;
} }
}); }));
return $path; return $path;
} }
foreach ($additionalTheme in (Get-UserConfig "oh-my-posh.additionalThemes")) { foreach ($additionalTheme in (Get-UserConfig -UserName "$user" "oh-my-posh.additionalThemes")) {
Write-Host "creating theme $additionalTheme" Write-Host "creating theme $additionalTheme"
$null = New-Theme $additionalTheme; $null = New-Theme $additionalTheme;
} }
@ -63,7 +72,14 @@ Start-SoftwareInstaller @PSBoundParameters `
[System.Environment]::SetEnvironmentVariable($varName, "%AppData%/$([System.IO.Path]::GetRelativePath($env:AppData, $theme))", "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 ($theme).Replace("~", "{{ .Home }}"); $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;
} }
} }
}; };

View file

@ -73,8 +73,11 @@ $null = New-Module {
[string] $User [string] $User
) )
$flags = @();
if ($User) { if ($User) {
$path = "$($IsWindows ? "~" : "$(sudo -u $User bash -c "realpath ~")")/.aliae.yaml"; $flags = @("-u", "$User")
$path = "$($IsWindows ? "~" : "$(sudo @flags bash -c "realpath ~")")/.aliae.yaml";
} else { } else {
$path = Get-GlobalConfigPath; $path = Get-GlobalConfigPath;
} }
@ -87,9 +90,9 @@ $null = New-Module {
Set-Item "Env:\$key" $variables[$key]; Set-Item "Env:\$key" $variables[$key];
} }
sudo -u $using:User cp $using:path $file; sudo @using:flags pwsh -CommandWithArgs 'Get-Content -Raw $args[0]' $using:path | Set-Content $file;
yq -yi $using:Script $file; yq -yi $using:Script $file;
sudo -u $using:User cp $file $using:path; sudo @using:flags pwsh -CommandWithArgs 'Set-Content $args[0] -Value $args[1]' $using:path (Get-Content -Raw $file);
Remove-Item $file; Remove-Item $file;
} | Receive-Job -Wait; } | Receive-Job -Wait;
} }