Set Ubuntu as default Windows Terminal profile

This commit is contained in:
Fabio Scotto di Santolo
2026-04-02 16:48:03 +02:00
parent ebea6c2bd8
commit 39c3a2287d
2 changed files with 32 additions and 0 deletions

View File

@@ -192,3 +192,34 @@
loop: "{{ windows_vscode_extensions | default([]) }}"
loop_control:
label: "{{ item }}"
- name: Set Windows Terminal default profile to Ubuntu
tags: [packages, wsl]
ansible.windows.win_powershell:
script: |
$terminalSettingsPath = Join-Path $env:LOCALAPPDATA 'Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json'
if (-not (Test-Path $terminalSettingsPath)) {
throw 'Windows Terminal settings.json was not found. Launch Windows Terminal once before applying the default profile configuration.'
}
$settings = Get-Content -Path $terminalSettingsPath -Raw | ConvertFrom-Json
if ($null -eq $settings.profiles -or $null -eq $settings.profiles.list) {
throw 'Windows Terminal settings.json does not contain a profiles.list section.'
}
$targetProfile = $settings.profiles.list |
Where-Object { $_.name -eq '{{ windows_terminal_default_profile_name }}' } |
Select-Object -First 1
if ($null -eq $targetProfile) {
throw "Windows Terminal profile '{{ windows_terminal_default_profile_name }}' was not found. Ensure the Ubuntu WSL profile exists in Windows Terminal first."
}
if ($settings.defaultProfile -eq $targetProfile.guid) {
$Ansible.Changed = $false
return
}
$settings.defaultProfile = $targetProfile.guid
$settings | ConvertTo-Json -Depth 100 | Set-Content -Path $terminalSettingsPath -Encoding utf8
$Ansible.Changed = $true