Code Monkey home page Code Monkey logo

get-childitemcolor's People

Contributors

asidlo avatar danielcarmingham avatar joonro avatar jqly 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

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

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.

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?

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

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

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

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

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

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

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

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)

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.

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.

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.

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

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

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

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.

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

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.

`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
[...]

Fails inside OneDrive

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

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

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

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.