Giter VIP home page Giter VIP logo

get-childitemcolor's Introduction

Get-ChildItemColor

Get-ChildItemColor provides colorization of outputs of Get-ChildItem Cmdlet of PowerShell. It is based on Tim Johnson’s script, another script by the PowerShell Guy, and PSColor.

It provides two main functionalities:

  1. Get-ChildItemColor, which adds coloring to the output of Get-ChildItem.
  2. Get-ChildItemColorFormatWide, which is colored version of Get-ChildItemColor | Format-Wide. This uses Write-Host to output coloring, because Get-ChildItemColor | Format-Wide does not allow multiple colors in one line.

Get-ChildItemColor has the following features:

  • Both functions support pipelines — they are pipeline-aware, so they just return untouhed output of Get-ChildItem when used as a part of a pipeline.
  • As of v3.0.0, it no longer overloads Out-Default, and thus does not have unintended consequences.
  • Both functions work as intended inside OneDrive directories.

Screenshots

Get-ChildItemColor

./screenshots/Get-ChildItemColor.png

Get-ChildItemColorFormatWide (ls equivalent)

./screenshots/Get-ChildItemColorFormatWide.png

Install

  • The wiki has additional instructions and examples.

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 run Install-Module Get-ChildItemColor.

Install from GitHub

After cloning the repo or downloading the files, you can put files in /src folder into Get-ChildItemColor folder under your PSModulePath (e.g., $ENV:UserProfile\Documents\PowerShell\Modules for PowerShell 6 and later). The master branch always contains the latest release version.

Install from Chocolatey

The module is available as a Chocolatey package. Install it using choco install get-childitemcolor.

Usage

When you import the module:

Import-Module Get-ChildItemColor

it provides two functions, Get-ChildItemColorFormatWide and Get-ChildItemColor.

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):

If (-Not (Test-Path Variable:PSise)) {  # Only run this in the console and not in 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.

Both functions have the following optional switches:

-File
Show only files.
-Directory
Show only directories.

Get-ChildItemColor has the following optional switch:

-HumanReadableSize
Unix style size string (e.g. M instead of MB, K instead of KB etc) (thanks to kforeverisback)

Get-ChildItemColorFormatWide has the following optional switches:

-HideHeader
Supress printing of headers (path on top).
-TrailingSlashDirectory
Add a trailing slash to directory names.

Note that if you want to use these switches as default, you have to define a function. For example,

function Get-ChildItemColorForceWideHHTS {
    	Get-ChildItemColorFormatWide -HideHeader -TrailingSlashDirectory -Force $Args[0]
}

Set-Alias ls Get-ChildItemColorForceWideHHTS -option AllScope

[fn:pathProfile] $Home\[My ]Documents\PowerShell\Profile.ps1 or $Home\[My ]Documents\WindowsPowerShell\Profile.ps1

[fn:pathProfileISE] $Home\[My ]Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1

Customizing color

One can dynamically change the color scheme for different items, thanks to asidlo’s contribution. See the example below.

# Change color for directories to Blue
$GetChildItemColorTable.File['Directory'] = "Blue"

# Change color for executables to Green
ForEach ($Exe in $GetChildItemColorExtensions['ExecutableList']) {
    $GetChildItemColorTable.File[$Exe] = "Green"
}

Adding a new category

One can create a new category and assign colors easily like the example below.

$GetChildItemColorExtensions['OfficeList'] = @(
    ".docx",
    ".pdf",
    ".pptx",
    ".xlsx"
)

ForEach ($Extension in $GetChildItemColorExtensions['OfficeList']) {
    $GetChildItemColorTable.File.Add($Extension, "Green")
}

Customizing vertical space

You can adjust the vertical spacing using $Global:GetChildItemColorVerticalSpace. Default is 1 (PowerShell’s default is 2).

$Global:GetChildItemColorVerticalSpace = 1

Authors

Changelog

  • This section only contains old logs. See Releases for newer changelog.

v2.4.0

  • Add HideHeader switch to Get-ChildItemColorFormatWide (#29)

v2.3.0

  • Better handling of header printout (#41)

v2.2.2

  • Add instructions about adding a new category.

v2.2.1

v2.2.0

  • Fix #27, Display issue with Chinese. (Thanks to shiena)

v2.1.1

  • BUGFIX: Print directory names correctly when -Recurse option is used

v2.1.0

  • Re-organize folder structure

v2.0.0

  • Incorporate PSColor’s implementation of coloring the output of Get-ChildItem.
  • Add $Global:GetChildItemColorVerticalSpace option.

v1.3.1

  • PR #21: Added ReparsePoint (symlink) detection, matched color scheme with Linux (thanks to cmilanf)
  • Make empty lines consistent between Get-ChildItemColor and Get-ChildItemColorFormatWide (Fixes #17)

v1.3.0

  • PR #23: Added customizable color output. (thanks to asidlo)
  • Improve README

v1.2.3

  • Add LICENSE

v1.2.2

  • Improve README (#15)
  • Beautify code

v1.2.1

  • PR #13: Fallback to Gray when no OriginalForegroundColor (thanks to mikesigs)
  • PR #12: Fix a typo (thanks to jqly)

v1.2.0

  • Robust to non-file entries (Issue #10)

v1.1.0

  • Revert back to previous implementation of Get-ChildItemColorFormatWide

v1.0.0

  • The script changes $Host.UI.RawUI.ForegroundColor only and keep the item object intact
  • Get-ChildItemColorFormatWide is basically Get-ChildItemColor | Format-Wide

v0.5.3

  • Better performance by reducing if’s
  • Proper printing of DirectoryEntry for FormatWide case

v0.5.2

  • Published on PowerShellGallery
  • Refactoring; separate out two functions

v0.4.2

  • Make it a PowerShell module

v0.4.1

  • Returns vanila Get-Childitem results for DictionaryEntry cases.

v0.4.0

  • 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)

get-childitemcolor's People

Contributors

asidlo avatar danielcarmingham avatar joonro avatar jqly avatar kforeverisback avatar mikesigs avatar nitin88 avatar pauby avatar shiena avatar theuserbl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

get-childitemcolor's Issues

Issue when attempting to use in PSDrives

Added this to my profile and updated my alias list for day to day use

seems to work as expected in folders but PSDrives return odd errors
I switched to WSMAN: to get this one as it only has one item to return
Useful.ps1 is a file I dot source in my profile to bring in a bunch of functions (including this one)

Index operation failed; the array index evaluated to null.
At C:\Data\PSRoot\Useful.ps1:67 char:13

  •         $c = $color_table[$_.Extension]
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : NullArrayIndex

You cannot call a method on a null-valued expression.
At C:\Data\PSRoot\Useful.ps1:111 char:13

  •         Write-Host ("{0,-7} {1,25} {2,10} {3}" -f $_.mode,
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

Version 2.2.1 not uploaded to PowerShell Gallery

Version 2.2.1 was released 14 days ago (thank you to those who contributed and to @joonro for taking a little time to make a new release!), but this release was not pushed to PowerShell Gallery.

When you have time, please upload this version to PowerShell Gallery.

Unable to find type [uint] on Windows PowerShell 5

Running version 3.2.1 of Get-ChildItemColor command in Windows Powershell 5.1 results in the following error:

PS C:\ > Get-ChildItemColor
Unable to find type [uint].
At C:\Program Files\WindowsPowerShell\Modules\get-childitemcolor\3.2.1\Get-ChildItemColor.psm1:231 char:5
+     [uint]
+     ~~~~~~
    + CategoryInfo          : InvalidOperation: (uint:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Replacing the referenced [uint] with [UInt32] in Get-ChildItemColor.psm1 allows the script run.

According to the documentation, [uint] and [UInt32] are both defined as accelerators for [System.UInt32] in PowerShell Core, but only [UInt32] is defined in Windows PowerShell 5.1.

Fails inside OneDrive

Hi, it seems to fail if you navigate to OneDrive folders, it just keeps the default color scheme?

Performance, etc.

Hi there,

i really appreciate your effort but i have to admit that your script is a complete mess. There are so many performance issues and also it seems that no coding standard was used. Even the naming convention of the whole script/function is wrong: Get-ChildItem-Color should be Get-ChildItemColor.

Please have a look at PSColor for a much more better (and faster) solution.
Even this 8 year old script solves it way better then your version: Get-ChildItemColor

I wouldn't recommend using it and normally would make a pull request... But since this is a complete mess it would be pointless. Maybe a short sentence in the readme would be helpful.

Cannot bind parameter 'ForegroundColor'. Cannot convert value "" to type "System.ConsoleColor".

I get the following error after importing the module and running gci/ls.
Have I missed something or is something else causing this?

gci : Cannot bind parameter 'ForegroundColor'. Cannot convert value "" to type "System.ConsoleColor".
Error: "The identifier name  cannot be processed because it is either too similar or identical to the following enumerator names:
 Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White.
Use a more specific identifier name."       
At line:1 char:1                                                                                       
+ gci                                                                                                  
+ ~~~                                                                                                  
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException          
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetChildItemCommand

Is it possible to get an `ll` equivalent?

I've been wanting to make my linux shells and (windows) powershell core shells look as similar as possible and this module is the first thing that pops up on every search combo i tried - Just shows you how useful this library is, so thanks :]

One thing I'm missing and wasn't entirely sure i understood if possible or not from the README - Is it possible to get an ll equivalent? i.e. like the wide example, just with coloring only on the Name property rather than all the others.

Ability to set output colors

Hi! Thanks for such a great extension to Powershell - it is really helping in daily work.

I was wondering if it would be possible to change the output colors on the go? Perhaps similarly to the Oh-My-Posh solution where we have a set of variables available to customize.

> $ThemeSettings.Colors

Name                           Value
----                           -----
VirtualEnvForegroundColor      White
VirtualEnvBackgroundColor      Red
PromptHighlightColor           DarkBlue
PromptForegroundColor          White
GitForegroundColor             Black
SessionInfoBackgroundColor     Black
GitDefaultColor                DarkGreen
PromptSymbolColor              White

Unicode char in filename causes UInt32 error

Hello,

I have a file in a directory that has unicode char 0x2019 ("Right single quotation mark") in its filename.

This error is generated when trying to list the content via Get-ChildItemColor:

Cannot convert value "-3687" to type "System.UInt32". Error: "Value was either too large or too small for a UInt32."

Original error:
image

I located the referenced original C code and changed the logic to more closely match it and that appears to work for me. I tested both with my original char (0x2019) and a wide char (0xf900) on win 11 with pwsh core 7.2.2.

Here is that change:
DanielCarmingham@e50aabd

If you're good with this, I'll PR it back to the repo...

Thanks,
Daniel

Errors on registry provider

When attempting to gci in a registry folder HKCU: for example

(Elevated) ebelew@SEADW2971 : HKCU:\ : 5/3/2017 2:51:10 PM :
> ls
Exception calling "ContainsKey" with "1" argument(s): "Key cannot be null.
Parameter name: key"
At C:\Program Files\WindowsPowerShell\Modules\Get-ChildItemColor\1.1.0\Get-ChildItemColor.psm1:100 char:17
+             If ($ColorTable.ContainsKey($Item.Extension)) {
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentNullException

Index operation failed; the array index evaluated to null.
At C:\Program Files\WindowsPowerShell\Modules\Get-ChildItemColor\1.1.0\Get-ChildItemColor.psm1:107 char:9
+         $Color = $ColorTable[$Key]
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArrayIndex

Write-Host : Cannot bind parameter 'ForegroundColor' to the target. Exception setting "ForegroundColor": "Cannot
convert null to type "System.ConsoleColor" due to enumeration values that are not valid. Specify one of the following
enumeration values and try again. The possible enumeration values are "Black,DarkBlue,DarkGreen,DarkCyan,DarkRed,DarkMa genta,DarkYellow,Gray,DarkGray,Blue,Green,Cyan,Red,Magenta,Yellow,White"."
At C:\Program Files\WindowsPowerShell\Modules\Get-ChildItemColor\1.1.0\Get-ChildItemColor.psm1:124 char:52
+         Write-Host ("{0,-$pad}" -f $towrite) -Fore $Color -NoNewLine: ...
+                                                    ~~~~~~
    + CategoryInfo          : WriteError: (:) [Write-Host], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.WriteHostCommand

ls command failed for special marks: Sort-Object and InvalidArgument errors

There's no problem to run l, however, to run ls failed on PowerShell 7.0.1.
At first, there are Sort-Object errors like

Sort-Object: C:\Users\Yihua\Documents\PowerShell\Modules\Get-ChildItemColor\2.2.0\Get-ChildItemColor.psm1:60
Line |
  60 |  … ject Name | Sort-Object { LengthInBufferCells("$_") } -Descending | S …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot convert value "-2171" to type "System.UInt32". Error: "Value was either too large or too small
     | for a UInt32."

The error repeats with values "-2171", "-3684", and "-3692" for many times. Then, after listing all the folders (directory), there are InvalidArgument errors like:

InvalidArgument: C:\Users\Yihua\Documents\PowerShell\Modules\Get-ChildItemColor\2.2.0\PSColorHelper.ps1:39
Line |
  39 |      [bool]$isWide = $Char -ge 0x1100 -and
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot convert value "-3684" to type "System.UInt32". Error: "Value was either too large or too small
     | for a UInt32."

The error repeats with values "-3684", "-2171", "-3683", "-3692", "3688", and "-3687" for many times.

After many experiments, I found that ls command worked well for most folders but for certain situation it failed. The error information shows only before files with names that containing SBC case of quotation marks (both double and single) (“,‘), star marks (★, ※, ☆), ellipsis dots (……), dash mark (——), arrow marks (↑↓←→), tick mark (√), and shape marks (○, △, □). All other SBC and special marks work correctly. Among them, quotation marks, ellipsis dots, and dash marks are in common use.

Previous command error status is discarded

I have just noticed that this module interfere with the PowerShell error status.

Expected behavior (without the Get-ChildItemColor module)

PS > python -c "exit(1)"
PS > echo $?
False

Actual behavior (with the Get-ChildItemColor module)

PS > python -c "exit(1)"
PS > echo $?
True

Fails when used in conjunction with the New-Junction command in PSCX

When invoked by the successful output of of the New-Junction command from the PowerShell Community Extensions module (https://github.com/Pscx/Pscx/) this error is thrown

New-Junction -TargetPath D:\Literary\unsorted\webcomic -LiteralPath D:\LitShare\unsorted_webcomic

FileInfo : You cannot call a method on a null-valued expression.
At C:\Users\Chirishman\Documents\WindowsPowerShell\Modules\Get-ChildItemColor\2.2.0\Get-ChildItemColor.psm1:182
char:17
+                 FileInfo $_
+                 ~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [FileInfo], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull,FileInfo

Upon debugging the inner exception in FileInfo is:

You cannot call a method on a null-valued expression.
At C:\Users\Administrator\Documents\WindowsPowerShell\Modules\Get-ChildItemColor\2.2.0\FileInfo.ps1:33 char:5
+     $ParentName = $Item.PSParentPath.Replace("Microsoft.PowerShell.Co ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Stepping into FileInfo I find that the PSParentPath property is not present, though the Parent property is there

$_| select *


Mode              : d----l
BaseName          : ebooks
Target            : {D:\Literary\ebooks\}
LinkType          : Junction
Name              : ebooks
FullName          : D:\LitShare\ebooks
Parent            : LitShare
Exists            : True
Root              : D:\
Extension         :
CreationTime      : 1/26/2024 12:28:25 PM
CreationTimeUtc   : 1/26/2024 5:28:25 PM
LastAccessTime    : 1/26/2024 12:28:25 PM
LastAccessTimeUtc : 1/26/2024 5:28:25 PM
LastWriteTime     : 1/26/2024 12:28:25 PM
LastWriteTimeUtc  : 1/26/2024 5:28:25 PM
Attributes        : Directory, ReparsePoint

I believe that this is happening because the New-Junction command is implemented as a DLL and is not automatically appending that extra property

get-command New-Junction |select *


HelpUri             :
DLL                 : C:\Program Files\WindowsPowerShell\Modules\Pscx\3.3.2\Pscx.dll
Verb                : New
Noun                : Junction
HelpFile            : C:\Program Files\WindowsPowerShell\Modules\Pscx\3.3.2\Pscx.dll-Help.xml
PSSnapIn            :
Version             : 3.3.2
ImplementingType    : Pscx.Commands.IO.Ntfs.NewJunctionCommand
Definition          :
                      New-Junction [-LiteralPath] <PscxPathInfo> [-TargetPath] <PscxPathInfo> [-WhatIf] [-Confirm]
                      [<CommonParameters>]

DefaultParameterSet :
OutputType          : {}
Options             : ReadOnly
Name                : New-Junction
CommandType         : Cmdlet
Source              : Pscx
Visibility          : Public
ModuleName          : Pscx
Module              : Pscx
RemotingCapability  : PowerShell
Parameters          : {[LiteralPath, System.Management.Automation.ParameterMetadata], [TargetPath,
                      System.Management.Automation.ParameterMetadata], [Verbose,
                      System.Management.Automation.ParameterMetadata], [Debug,
                      System.Management.Automation.ParameterMetadata]...}
ParameterSets       : {[-LiteralPath] <PscxPathInfo> [-TargetPath] <PscxPathInfo> [-WhatIf] [-Confirm]
                      [<CommonParameters>]}

I think this could be solved by adding a fallback to dropping everything after the last slash in FullName if PSParentPath is missing though I've also reported it on that repo as a bug (Pscx/Pscx#99)

Length-format differs

There are some differences to Get-ChildItem.

A minor one is, that the date begins two spaces to early and the text "LastWriteTime" one space to early.

Harder is the complete "Length"-column:
Directories, which having in Get-ChildItem no length-output and also on the cmd.exe dir command never hand an length, have in Get-ChildItemColor a length of 1.
And bigger files are shown in "KB", "MB" and "GB", which makes them harder to differ, then giving out the exact byte-number of the file.

diff

actual PowerShell have alredy coloring itself

I have had used PowerShell 7.1.4 before. And that have no coloring of Get-ChildItem.

But now I have tried out the actual PowerShell 7.3.0-preview.5. And that have a coloring for the exe-files, the directories, *.zip files, ps1 files, psm1 files, psd1 files and possible other.

dll files, txt files, etc. are there non colored. Who that wants needing possibly still Get-ChildItemColor. But for all other is coloring in the original Get-ChildItem already included.

Broken output from Select-String -Context

When using Get-ChildItemColor, the default console text output from Select-String doesn't show the captured context. Also, it shouldn't display the file name if the input is stream.
Importing module with -NoClobber seems to fix this issue, but it also disables general coloring.

Test:
1, 2 | Select-String 1 -Context 1

Expected:

> 1
  2

Actual:
InputStream:1:1

Unable to use grep when overriding ls with Set-Alias

After implementing the script, I'm no longer able to pipe to grep. Instead, the ls command will list the entire directory structure. Current work around is to use the Get-ChildItem cmdlet instead.

Example--

(Elevated) talaniz@OZL-TONY : ~\test : 8/26/2016 4:17:51 PM :
> ls

    Directory: C:\Users\talaniz\test

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        11/17/2013   9:47 PM        380 .project
-a---        11/17/2013  10:00 PM       1300 index.html

(Elevated) talaniz@OZL-TONY : ~\test : 8/26/2016 4:17:52 PM :
> ls | grep index

    Directory: C:\Users\talaniz\test

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        11/17/2013   9:47 PM        380 .project
-a---        11/17/2013  10:00 PM       1300 index.html

Set Alias - The term 'Get-ChildItem-Color' is not recognized

ls : The term 'Get-ChildItem-Color' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • ls
  • ~~
    • CategoryInfo : ObjectNotFound: (Get-ChildItem-Color:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

Windows 10
Used example to setup profile with Import and Set-Alias

Out-Default function breaks $?

The definition of Out-Default seems to be breaking the usage of $?.

For example, if I run an invalid command in pwsh -noprofile, I get this:

PS C:\Users\chenxiaolong> git asdf
git: 'asdf' is not a git command. See 'git --help'.

The most similar command is
        add
PS C:\Users\chenxiaolong> echo $?
False

If I import Get-ChildItemColor (version 2.1.1), then $? stops working properly:

PS C:\Users\chenxiaolong> Import-Module Get-ChildItemColor
PS C:\Users\chenxiaolong> git asdf
git: 'asdf' is not a git command. See 'git --help'.

The most similar command is
        add
PS C:\Users\chenxiaolong> echo $?
True

If I remove the Out-Default function, then things work again, but of course, no more ls colors:

PS C:\Users\chenxiaolong> Remove-Item Function:Out-Default
PS C:\Users\chenxiaolong> git asdf
git: 'asdf' is not a git command. See 'git --help'.

The most similar command is
        add
PS C:\Users\chenxiaolong> echo $?
False

Get-ChildItemColor directory isn't grey like Get-ChildItemColorFormatWide

Love this feature first of all. Only a minor trivial point I had noticed:

The output of the Directory name in Get-ChildItemColor is the same colour as what the first item in the list is (i.e. yellow in the case of a directory being the first item). While for Get-ChildItemColorFormatWide is it grey. Is this by design?

Display issue with Chinese

Hi, thanks for developing such an awesome script. I didn't test for other languages, but when files name with English and Chinese, the output of ls will be disordered. Hope this can be fixed later.
Snipaste_2019-08-11_16-22-30

Directory and column descriptions only show up on first launch

The "Directory" and the "Mode", "LastWriteTime", "Length" and "Name" text only show up on the first launch of Get-ChildItemColor in the directory. After chaning the dir the headline text shows up again. This doesn't happen with Get-ChildItemColorFormatWide

Cmder

Installation warns that Out-Default already is defined

When installing the module, powershell warns that Out-Default is already available and that Get-ChildItemColor might overwrite it. Should the instructions be updated to say to use the -AllowClobber option?

1|9:42 PM] [C:\WINDOWS\system32]PS>Install-Module Get-ChildItemColor                                                                                                                                                                           Untrusted repository                                                                                                    You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a
PackageManagement\Install-Package : The following commands are already available on this system:'Out-Default'. This
module 'Get-ChildItemColor' may override the existing commands. If you still want to install this module
'Get-ChildItemColor', use -AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package],
   Exception
    + FullyQualifiedErrorId : CommandAlreadyAvailable,Validate-ModuleCommandAlreadyAvailable,Microsoft.PowerShell.Pack
   ageManagement.Cmdlets.InstallPackage

Compatible with `Get-ChildItem` and add `-h` or `-HumanReadable` flag similar to `ls -h` in Unix

Thanks for this awesome module! I use it almost daily.
It gives me good color output as well as human-readable sizes! Awesome!!

Currently the Get-ChilditemColor* is not output compatible with the Get-ChildItem.

Get-ChilditemColor outputs:

    Directory:  C:\Users\kushal

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d-r--          8/3/2024   3:03 AM        1   Searches
d----          9/8/2020  11:49 AM        1   source
d-r--         7/28/2024   7:36 AM        1   Videos
d----         9/19/2023  10:35 AM        1   vimfiles
d----          6/2/2024   4:32 PM        1   VirtualBox VMs
d----          1/7/2022   9:51 AM        1   wslu
d----          4/5/2023   2:41 PM        1   XLensDemo_assets
-a---          3/8/2024   2:12 AM    36.68KB _viminfo
-a---          3/6/2023   3:20 PM     1.65KB _vimrc
-a---         2/13/2023   1:01 PM     7.67KB .bash_history
-a---         1/12/2024  12:01 AM       16   .esd_auth
-a---        12/22/2022   3:59 PM       56   .git-cred-windows
-a---         12/8/2021  11:21 PM      153   .git-user-info
-a---          2/1/2024  12:49 PM     2.05KB .gitconfig
-a---          2/1/2024  12:49 PM       27   .gitconfig-windows

Notice the length column, where it is different from Get-ChildItem output. In Get-ChildItem:

  1. The directory entries doesn't show 1 as size.
  2. The file size always shows bytes instead of human-readable format (KB,MB,GB etc).

The size item makes it harder to parse output in pipe.
Not sure if Get-ChildItemColor was intended to be output compatible with the original Get-ChildItem.
Maybe we can fix the directory size (1) and add a -h and/or -HumanReadable flag similar to Unix's ls -h that'll show KB,MB,GB size but by default will show bytes.

`Get-ChildItemColorFormatWide` error on PowerShell ISE

Error occurs only in PowerShell ISE:

Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero.
Parameter name: length"
At C:\Users\thorsten\Documents\PowerShell\Modules\Get-ChildItemColor\1.2.1\Get-ChildItemColor.psm1:126 char:13
+             $toWrite = $toWrite.Substring(0, $pad - 3) + "..."
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException
 
Error formatting a string: Input string was not in a correct format..
At C:\Users\thorsten\Documents\PowerShell\Modules\Get-ChildItemColor\1.2.1\Get-ChildItemColor.psm1:129 char:9
+         Write-Host ("{0,-$pad}" -f $toWrite) -Fore $Color -NoNewLine: ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({0,--1}:String) [], RuntimeException
    + FullyQualifiedErrorId : FormatError
[...]

Support human-readable file size output

Hi,
thanks for this great cmdlet. I'd love to have human-readable file size output instead of the simple byte count that PowerShell provides. A way to do this is described here. However, when using format-table with Get-ChildItemColor, the colorization is lost. Any way around this?
Thanks, Jan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.