From 4ac242875535da8bcd0bbecf4fab25714bc50487 Mon Sep 17 00:00:00 2001 From: Zackarias Montell Date: Tue, 11 Aug 2026 10:48:01 +0200 Subject: [PATCH] Fixing pwsh to wsl docker setup --- .theme.omp.json | 215 ++++++++++++++++++++++++++++++-------- Update-WSLDockerProxy.ps1 | 36 +++++-- 2 files changed, 201 insertions(+), 50 deletions(-) diff --git a/.theme.omp.json b/.theme.omp.json index 9f9315e..cb07ff4 100644 --- a/.theme.omp.json +++ b/.theme.omp.json @@ -1,45 +1,97 @@ { "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", "palette": { - "os": "#ACB0BE", - "closer": "p:os", - "pink": "#F4B8E4", - "lavender": "#BABBF1", - "blue": "#8CAAEE" + "base": "#1E1E2E", + "blue": "#89B4FA", + "crust": "#11111B", + "false": "p:red", + "flamingo": "#F2CDCD", + "git": "p:lavender", + "go": "p:mauve", + "green": "#A6E3A1", + "haskell": "p:mauve", + "julia": "p:mauve", + "lavender": "#B4BEFE", + "lua": "p:mauve", + "mantle": "#181825", + "maroon": "#EBA0AC", + "mauve": "#CBA6F7", + "os-bg": "p:base", + "os-fg": "p:green", + "overlay0": "#6C7086", + "overlay1": "#7F849C", + "overlay2": "#9399B2", + "path": "p:green", + "peach": "#FAB387", + "pink": "#F5C2E7", + "python": "p:mauve", + "red": "#F38BA8", + "root-bg": "p:yellow", + "root-fg": "p:base", + "rosewater": "#F5E0DC", + "rust": "p:mauve", + "sapphire": "#74C7EC", + "sky": "#89DCEB", + "subtext0": "#A6ADC8", + "subtext1": "#BAC2DE", + "surface0": "#313244", + "surface1": "#45475A", + "surface2": "#585B70", + "teal": "#94E2D5", + "text": "#CDD6F4", + "time": "p:overlay1", + "true": "p:green", + "yellow": "#F9E2AF", + "docker": "p:peach", + "k8s": "p:red" }, + "transient_prompt": { + "template": "{{ now | date \"15:04:05\" }} {{ if gt .Code 0 }}❯{{ else }}❯{{ end }} ", + "foreground": "p:time" + }, + "console_title_template": "{{ .Shell }} in {{ .PWD }}", "blocks": [ { + "type": "prompt", "alignment": "left", "segments": [ { - "foreground": "p:os", - "style": "plain", - "template": "{{.Icon}} ", - "type": "os" - }, - { - "foreground": "p:blue", - "style": "plain", - "template": "{{ .UserName }}@{{ .HostName }} ", - "type": "session" - }, - { - "foreground": "p:pink", "properties": { - "folder_icon": "..\ue5fe..", - "home_icon": "~", - "style": "agnoster_short" + "cache_duration": "none", + "windows": "\ue70f", + "ubuntu": "\udb80\udf3d" }, + "template": "{{ .Icon }}", + "foreground": "p:os-fg", + "background": "p:os-bg", + "type": "os", "style": "plain", - "template": "{{ .Path }} ", - "type": "path" + "foreground_templates": [ + "{{ if .Root }}p:root-fg{{ end }}" + ], + "background_templates": [ + "{{ if .Root }}p:root-bg{{ end }}" + ] + }, + { + "properties": { + "cache_duration": "none", + "folder_icon": "..", + "home_icon": "~", + "style": "folder" + }, + "template": " {{ .Path }} ", + "foreground": "p:path", + "type": "path", + "style": "powerline" }, { - "foreground": "p:lavender", "properties": { "branch_icon": "\ue725 ", + "cache_duration": "none", "cherry_pick_icon": "\ue29b ", "commit_icon": "\uf417 ", + "fetch_stash_count": false, "fetch_status": false, "fetch_upstream_icon": false, "merge_icon": "\ue727 ", @@ -49,39 +101,120 @@ "tag_icon": "\uf412 " }, "template": "{{ .HEAD }} ", - "style": "plain", - "type": "git" + "foreground": "p:git", + "type": "git", + "style": "plain" }, { - "background": "#FFDE57", - "foreground": "#111111", - "powerline_symbol": "\ue0b0", "properties": { - "display_mode": "environment", - "fetch_virtual_env": true, - "home_enabled": true + "cache_duration": "none" }, + "template": "\uf308 {{if matchP \"unix:///run/user/1000//docker.sock\" .Context }}Local{{ else }}{{.Context}}{{ end }} ", + "foreground": "p:docker", + "type": "docker", + "style": "plain" + }, + { + "type": "kubectl", + "style": "powerline", + "foreground": "p:k8s", + "template": "󱃾 {{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}} ", + "options": {} + }, + { + "properties": { + "cache_duration": "none" + }, + "template": "\ue627 {{ if not .Error }}{{ .Full }}{{ end }} ", + "foreground": "p:go", + "type": "go", + "style": "plain" + }, + { + "properties": { + "cache_duration": "none" + }, + "template": "\ue61f {{ if not .Error }}{{ .Full }}{{ end }} ", + "foreground": "p:haskell", + "type": "haskell", + "style": "plain" + }, + { + "properties": { + "cache_duration": "none" + }, + "template": "\ue624 {{ if not .Error }}{{ .Full }}{{ end }} ", + "foreground": "p:julia", + "type": "julia", + "style": "plain" + }, + { + "properties": { + "cache_duration": "none" + }, + "template": "\ue620 {{ if not .Error }}{{ .Full }}{{ end }} ", + "foreground": "p:lua", + "type": "lua", + "style": "plain" + }, + { + "properties": { + "cache_duration": "none", + "display_default": false, + "display_mode": "context" + }, + "template": " \ue73c {{ if not .Error }}{{ if .Venv }}venv/{{ end }}{{ .Full }}{{ end }}", + "foreground": "p:python", + "type": "python", + "style": "plain" + }, + { + "properties": { + "cache_duration": "none" + }, + "template": "\ue7a8 {{ if not .Error }}{{ .Full }}{{ end }} ", + "foreground": "p:rust", + "type": "rust", + "style": "plain" + }, + { + "properties": { + "cache_duration": "none", + "style": "austin", + "threshold": 500 + }, + "template": " \udb81\udd1f {{ .FormattedMs }} ", + "foreground": "p:true", + "type": "executiontime", "style": "plain", - "template": " \ue235 {{ if .Venv }}({{ .Venv }}){{ end }} ", - "type": "python" + "foreground_templates": [ + "{{ if .Code }}p:false{{ end }}" + ] } ], - "type": "prompt" + "newline": true }, { + "type": "prompt", "alignment": "left", "segments": [ { + "properties": { + "always_enabled": true, + "cache_duration": "none" + }, + "template": "❯ ", + "foreground": "p:true", + "type": "status", "style": "plain", - "foreground": "p:closer", - "template": "\uf105", - "type": "text" + "foreground_templates": [ + "{{ if gt .Code 0 }}p:false{{ end }}" + ] } ], - "type": "prompt", "newline": true } ], - "final_space": true, - "version": 3 + "version": 3, + "shell_integration": true } diff --git a/Update-WSLDockerProxy.ps1 b/Update-WSLDockerProxy.ps1 index 56515d0..c13db62 100644 --- a/Update-WSLDockerProxy.ps1 +++ b/Update-WSLDockerProxy.ps1 @@ -3,13 +3,20 @@ # Usage: . .\Update-WSLDockerProxy.ps1 (dot-source to import the function) # Update-WSLDockerProxy (then call it) # Or just run the script directly and it will execute automatically. - function Update-WSLDockerProxy { [CmdletBinding()] param( - [int]$Port = 2375 + [int]$Port = 2375, + [string]$LogPath = "$env:TEMP\Update-WSLDockerProxy.log" ) + function Write-Log { + param([string]$Message) + $line = "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') $Message" + Write-Host $Message + Add-Content -Path $LogPath -Value $line + } + # Self-elevate if not running as admin if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host "Not running as admin, re-launching elevated..." -ForegroundColor Yellow @@ -22,27 +29,38 @@ function Update-WSLDockerProxy { return } - # Get current WSL IP - $WSL_IP = (wsl hostname -I 2>$null).Split(" ")[0].Trim() + # --- Get current WSL IP --- + # wsl.exe emits UTF-16 output with embedded null bytes when its stdout isn't + # attached to a real console (hidden window, scheduled task, self-elevated + # relaunch, etc). That corrupts naive string parsing (e.g. results in "W" + # instead of an IP). Strip null chars before parsing, and validate the + # result looks like an actual IPv4 address before using it. + $rawOutput = (wsl.exe hostname -I 2>$null) -join ' ' + $cleaned = ($rawOutput -replace "`0", '').Trim() + + $WSL_IP = $null + if ($cleaned) { + $candidates = $cleaned -split '\s+' | Where-Object { $_ -match '^\d{1,3}(\.\d{1,3}){3}$' } + $WSL_IP = $candidates | Select-Object -First 1 + } if (-not $WSL_IP) { - Write-Error "Could not get WSL IP. Is WSL running?" + Write-Log "ERROR: Could not get a valid WSL IP. Raw output was: '$rawOutput'" return } - Write-Host "WSL IP: $WSL_IP" -ForegroundColor Cyan + Write-Log "WSL IP: $WSL_IP" # Remove existing rule if present $existing = netsh interface portproxy show v4tov4 | Select-String ":$Port" if ($existing) { - Write-Host "Removing existing portproxy rule on port $Port..." -ForegroundColor Gray + Write-Log "Removing existing portproxy rule on port $Port..." netsh interface portproxy delete v4tov4 listenport=$Port listenaddress=127.0.0.1 | Out-Null } # Add new rule netsh interface portproxy add v4tov4 listenport=$Port listenaddress=127.0.0.1 connectport=$Port connectaddress=$WSL_IP | Out-Null - - Write-Host "Portproxy updated: 127.0.0.1:$Port -> ${WSL_IP}:$Port" -ForegroundColor Green + Write-Log "Portproxy updated: 127.0.0.1:$Port -> ${WSL_IP}:$Port" } # Run automatically if script is executed directly (not dot-sourced)