- This adds colors to the output of
Get-ChildItem
Cmdlet of PowerShell. It is based on Tim Johnson’s script and another script by the PowerShell Guy. - Before version 1.0.0, the script actually had used
Write-Host
to write colored items on console. Now it just changes$Host.UI.RawUI.ForegroundColor
and keep the item object intact. Hence, now one can use pipeline. (e.g.,Get-ChildItemColor | grep ".git"
). Get-ChildItemColorFormatWide
still usesWrite-Host
for output however. This is becauseGet-ChildItemColor | Format-Wide
does not allow multiple colors in one line. Hence, pipeline does not work withGet-ChildItemColorFormatWide
.
- It uses a hash table instead of regular expressions to specify colors
- Recognize the
DictionaryEntry
case (e.g.,Get-ChildItemColor env:
) - Color support for
| Format-Wide
format (ls
equivalent) with custom script
Install from PowerShellGallery
PowerShellGet is required, which is included in Windows 10 and WMF5. If you are using PowerShell V3 or V4, you will need to install PowerShellGet.
Then, you can simply run Install-Module Get-ChildItemColor
(or
Install-Module Get-ChildItemColor -Scope CurrentUser
).
Clone the repo in your PowerShell Module folder
($ENV:UserProfile\Documents\WindowsPowerShell\Modules
).
git clone https://github.com/joonro/Get-ChildItemColor.git
When you import the module:
Import-Module Get-ChildItemColor
it exposes two functions, Get-ChildItemColor
and Get-ChildItemColorFormatWide
.
You can add aliases to these functions for convenience. For example, I have the following in my profile[fn:pathProfile] (please do not put this into ISE profile[fn:pathProfileISE] as it does not work in ISE):
#verify this is the console and not the ISE
Import-Module Get-ChildItemColor
Set-Alias l Get-ChildItemColor -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
So l
yields colored output of Get-ChildItem
and ls
yields colored output
of Get-ChildItem | Format-Wide
equivalent.
[fn:pathProfile] $Home\[My ]Documents\WindowsPowerShell\Profile.ps1
[fn:pathProfileISE] $Home\[My ]Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
- Improve README (#15)
- Beautify code
- PR #13: Fallback to Gray when no
OriginalForegroundColor
(thanks to mikesigs) - PR #12: Fix a typo (thanks to jqly)
- Robust to non-file entries (Issue #10)
- Revert back to previous implementation of
Get-ChildItemColorFormatWide
- The script changes
$Host.UI.RawUI.ForegroundColor
only and keep the item object intact Get-ChildItemColorFormatWide
is basicallyGet-ChildItemColor | Format-Wide
- Better performance by reducing if’s
- Proper printing of
DirectoryEntry
forFormatWide
case
- Published on PowerShellGallery
- Refactoring; separate out two functions
- Make it a PowerShell module
- Returns vanila
Get-Childitem
results forDictionaryEntry
cases.
- Make function names consistent to the PowerShell naming convention (#8)
- Use parameters more consistently,
-Path
works with paths with spaces (#3), and-Force
works (#9)