PowerShell: Output of `ls` or ` Get-ChildItem` has unexpected bg color for directories names

Prerequisites

Steps to reproduce

Hello pwsh team,

Please check the screenshot below: image

I have empty profile file under Documents\PowerShell\Microsoft.PowerShell_profile.ps1 also no modules under Documents\PowerShell\Modules\ . Could you please tell me where else should i check for such configuration?

Thanks

Expected behavior

Directories names has a transparent background color

Actual behavior

Directories names has a blue background color

Error details

No response

Environment data

PS C:\Program Files> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.0
PSEdition                      Core
GitCommitId                    7.3.0
OS                             Microsoft Windows 10.0.19044
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Configure $PSStyle For example white directory color:

$PSStyle.FileInfo.Directory = "`e[38;2;255;255;255m"

Rephrasing out what was said above, for someone who is being bothered by this and is landing here out of the blue, and doesn’t quite grasp what is happening, hoping that it is a bit more clear.

  • Yes, since 7.3 the PowerShell started to add that background to directories
  • If you type in your PShell “$PSStyle”, you’ll get a list of some variables that you can customize, and the possible color codes
  • The variable that you are looking for, in the case of folders, is “FileInfo.Directory”
  • If you type what @237dmitry suggested directly in the Powershell, it will clear the background highlighting, while that shell session is active
  • To do it permanently, you can add it to your PowerShell profile, so that it is loaded every time

I found it a bit perplexing that a change like this was added, as the default behavior. Maybe there was a lot of people asking for it. Anyway, changing the background color of folders is just one of the options, it is actually pretty cool what can be done with PSStyle. I’ve found this blog post pretty good, explaining some neat things you can do.

You will discover some other colouring applied to items in directory output - which you probably don’t want either

if ($pstyle) {
  $psstyle.FileInfo.Directory = $psstyle.FileInfo.Executable = $psstyle.FileInfo.SymbolicLink  = "" 
  $PSStyle.FileInfo.Extension.Clear()
  $PSStyle.Formatting.TableHeader       = ""
  $PsStyle.Formatting.FormatAccent      = ""
}

Is a useful add on to many profiles. The powers that be believe most people want their directories to be blue because bash makes them blue, but it blue on black breaks the accessibility requirements for contrast so they have selected white on blue. A search should find the discussion on this. The important thing is you can set things exactly how you want them to be.

This did not work well for me - apparently missed this change and just thought it was broken.

image

Unclear why this is closed? Is it being fixed in new version?

I found it a bit perplexing that a change like this was added, as the default behavior. Maybe there was a lot of people asking for it.

I have a problem reading things when there is movement, unexpected colours and a few other things on the screen, and find unix/linux seemingly random use of colours makes it much more difficult to read. There is a demand from people coming from other shells to be able to get the same colours, in particular “blue” for directory. However blue text on black fails accessibility tests for people with more common eyesight problems - who need more contrast, hence this compromise. A decision was “what seemed like a good idea to a dev at the time” colours to be opt out rather than opt in, so that people would know colour was available. I still contend that finding the opt out leaves a few people who want it off frothing-at-the-mouth angry, where an opt in would have left those who missed their linux colours feeling mild disappointment… however that argument was lost long ago. I turn it off in my profile, and if I need to test with -noprofile I work with slight nausea and the reading speed of a small child 😦

@garretwilson the to turn all the colours off you can set $PSStyle.OutputRendering = “PlainText”

Otherwise the noticeable update in 7.3 is that $psstyle.FileInfo.Directory, $psstyle.FileInfo.Executable and $psstyle.FileInfo.SymbolicLink now contain escape sequences for Directories links and executables. You can choose your own if you don’t like the PowerShell team’s choice, I find none at all is best.

For other items $PSStyle.FileInfo.Extension holds the file extension and the escape sequence. Clear() removes them all. $PSStyle.FileInfo.Extension.Add(".JPG","$($PSStyle.Foreground.BrightCyan)") adds one. Again I find clear() gives the optimal combinations.

If you don’t like column headings and list labels in green then $PSStyle.Formatting.TableHeader and $PsStyle.Formatting.FormatAccent contain the ansi sequence for those and I find that no-sequence is better for me

As with so much, it’s very customizable if (like me) you don’t like the defaults.