Skip to content

Instantly share code, notes, and snippets.

@Iron-Wolf
Last active April 25, 2022 09:47
Show Gist options
  • Save Iron-Wolf/bebcb692a97d5c9175093c4f84868856 to your computer and use it in GitHub Desktop.
Save Iron-Wolf/bebcb692a97d5c9175093c4f84868856 to your computer and use it in GitHub Desktop.

Table of contents

1 - Troubleshoot

1.1 - WSL network errors

Cannot access outside world from WSL

Fix Internet access by manually adding DNS address :

# add DNS in resolv.conf
sudo sed -i '1s/^/nameserver 1.1.1.1\n/' /etc/resolv.conf
# make the file immutable
sudo chattr +i /etc/resolv.conf

Cannont access WSL app from outside

I have no clue how to solve that for now.
You can force a restart with wsl.exe --shutdown.

1.2 - IntelliJ bug

Slow debug mode

  • In Settings : Build, Execution, Deployment -> Debugger -> Data Views -> Java
  • Disable thoses options :
    • Enable alternative view for Collection classes
    • Enable 'toString()' object view

Improve QoL with back/forward

  • In Settings : Appearance & Behavior -> Menus ans Toolbars -> Navigation Bar Toolbar
  • Add thoses actions (from the Other folder) :
    • Back
    • Forward

Lombok error (should be fixed starting 2022 version)

  • Error : java: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
  • Correction :
    • In Setting : Build, Execution, Deployment -> Compiler -> Shared build process VM options
    • Add this parameter : -Djps.track.ap.dependencies=false

Remove wildcard imports (not entirely feasible)

  • In Settings : Editor -> Code Style -> Java -> Imports
  • Enable the option : Use single class import
  • Add 999 in thoses options :
    • Class count to use import with '*'
    • Names count to use static import with '*'

1.3 - Unable to bind port (Source)

A program can request a port that is somehow locked by Windows.
This bug appeared to me with Docker, but it is not related to Docker :

listen tcp :50051: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

To solve this, you can check if you have the issue (in PowerShell) :

# the port should not be used
netstat -aon
# but you should see it in a port exclusion range
netsh int ipv4 show excludedportrange protocol=tcp

This is probably an error in the dynamic port configuration :

# check the "Start Port"
netsh int ipv[46] show dynamicport tcp
# if not set to "49152", change it with
netsh int ipv[46] set dynamic tcp start=49152 num=16384

Other solutions : https://youtrack.jetbrains.com/issue/IDEA-238995

2.1 - Install

You can use choco (not in official documentation) :

choco install oh-my-posh
# test your install with
`oh-my-posh --print-shell`  

Install a font globaly with :
right clic .ttf > "Install for all users"
Most themes use glyphs (icons) implemented in fonts from NerdFont project.
Recommended font (not official) : Literation Mono.

2.2 - WindowsTerminal Config

Add this parameter in settings.json :

"profiles": {
    "defaults": {
        "fontFace": "LiterationMono NF"
    }
}

Color theme

Raspberry theme from Microsoft Doc :

Config
"schemes": [
    {
        "name" : "Raspberry",
        "background" : "#3C0315",
        "black" : "#282A2E",
        "blue" : "#0170C5",
        "brightBlack" : "#676E7A",
        "brightBlue" : "#80c8ff",
        "brightCyan" : "#8ABEB7",
        "brightGreen" : "#B5D680",
        "brightPurple" : "#AC79BB",
        "brightRed" : "#BD6D85",
        "brightWhite" : "#FFFFFD",
        "brightYellow" : "#FFFD76",
        "cyan" : "#3F8D83",
        "foreground" : "#FFFFFD",
        "green" : "#76AB23",
        "purple" : "#7D498F",
        "red" : "#BD0940",
        "white" : "#FFFFFD",
        "yellow" : "#E0DE48"
    }
]

2.3 - PowerShell Config

Change prompt (add line in $PROFILE file) :

Invoke-Expression `
(oh-my-posh --init `
--shell pwsh `
--config "$env:LOCALAPPDATA\Programs\oh-my-posh\themes\agnoster.omp.json")

It's seems that you have to restart the PC for vanilla Powershell to work. On my rig, powershell complained that the oh-my-posh was not accessible. As a workaround, you can specify the absolute path of the command.

Custom font

If you use the standard Powershell window, you will have some artifacts because the prompt need special icons that are not in the default font. As such, you must use a mono font.

  • You can download this version of Literation Mono Nerd Font which has been specifically fixed to be recognised as monospace on Windows.
    Choose the Literation Mono Nerd Font Complete Mono Windows Compatible ttf file from the zip.
  • then, modify the registry to add this to the list of fonts for terminal apps
$key = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont'
Set-ItemProperty -Path $key -Name '000' -Value 'LiberationMono NF'
  • Open PowerShell, right click the title bar > properties > Font > select your new font from the list.

2.4 - WSL Config

install :

wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64
chmod +x posh-linux-amd64

Change prompt (add line in ~/.bashrc) :

eval "$(~/posh-linux-amd64 --init --shell bash --config /mnt/<LOCALAPPDATA>/Programs/oh-my-posh/themes/agnoster.omp.json)"

Custom font

As well as Powershell terminal, you will need to change the font if you use the standrad WSL window. Follow the same rules as powershell part.

2.5 - VS Codium Config

Change font (in Settings) :
"terminal.integrated.fontFamily": "LiterationMono NF"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment