DEV Community

Cover image for Updating `ls` output display in WSL2 and Windows Terminal
Klee Thomas
Klee Thomas

Posted on

Updating `ls` output display in WSL2 and Windows Terminal

I've recently made the switch from Cmder with PowerShell to Window Terminal with WSL2 as my go to command line environment. It's great except for one thing, I find the way the ls command displays directories really hard to read the highlight colour mixed with the directory name has really low contrast. Changing the theme under the Windows Terminal settings changes the colours as a whole the highlighted style of the directories remains and is still difficult for me to read.

The display style is actually set by the Ubuntu environment. All the configuration for how the ls command should display variables is set in an environment variable LS_COLORS to see what is in there run echo $LS_COLORS the output will look like this:

$ echo $LS_COLORS
Enter fullscreen mode Exit fullscreen mode

This is a list of all the display information on how the different types of files should be displayed. It's in one of the format ext=x;yy;zz: where ext is the file type or extension x is a one digit representation of how to display the font, yy and zz are a 2 digit representation of the colour of the font and background respectively, ; delimits parameters within a set and : delimits between sets. All of the parameters are optional and the system seems to decide on the which to use based on if it's a valid input for that position, eg ext=1: will set the font weight to bold and ext=36: will set the colour to blue.

To make the directories display in a more readable fashion update the other writeable or ow property. This can be overwritten by adding it to the end of the environment variable string. LS_COLORS=$LS_COLORS:'ow36:' to set the out put for other writeable to blue with no background and make the text much more legible.

To make this change across all future terminal windows add export LS_COLORS=$LS_COLORS:'ow=36:' to the end of the ~/.bashrc file using echo "export LS_COLORS=\$LS_COLORS:'ow=36:'">>~/.bashrc. Don't forget to escape the $ or the current value of LS_COLORS will be exported instead of the variable name.

For more information on which codes relate to each colour see this answer on stack overflow

Top comments (0)