Giter Club home page Giter Club 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. Directly provide coloring outputs of Get-ChildItem by modifying Out-Default. Once the module is imported, Get-ChildItem’s output will be automatically colored. It does support pipeline (e.g., Get-ChildItem | grep ".git"). Also, now the directory name and the headers of its output have consistent colors. This is an adaptation of PSColor.
  2. It provides Get-ChildItemColorFormatWide, which uses Write-Host to output coloring. This is because Get-ChildItemColor | Format-Wide does not allow multiple colors in one line. As a result, pipeline does not work with Get-ChildItemColorFormatWide.

It also provides Get-ChildItemColor, which just changes $Host.UI.RawUI.ForegroundColor and keep the item object intact. This was the implementation before v2.0.0, and it does support pipeline. (e.g., Get-ChildItemColor | grep ".git"). The main shortcoming of this approach is that the directory name and the headers of its output have inconsistent colors.

Screenshot:

Get-ChildItem (Colorized)

./screenshots/Get-ChildItem.png

Get-ChildItemColorFormatWide (ls equivalent)

./screenshots/Get-ChildItemColorFormatWide.png

Get-ChildItemColor

./screenshots/Get-ChildItemColor.png

Install

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 -AllowClobber Get-ChildItemColor. Note that you need -AllowClobber option so Get-ChildItemColor may override the existing command Out-Default.

Install from GitHub

After cloning the repo, you can put files in /src folder into Get-ChildItemColor folder under your PowerShell Module folder ($ENV:UserProfile\Documents\WindowsPowerShell\Modules). The master branch always contains the latest release version.

Usage

When you import the module:

Import-Module Get-ChildItemColor

it provides a proxy function for Output-Default, so Get-ChildItem’s output will be automatically colored. In addition, it provides two functions, Get-ChildItemColorFormatWide and Get-ChildItemColor (the latter is unlikely to be useful, but remained intact just in case).

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-ChildItem -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

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"
}

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

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 joonro avatar jqly avatar mikesigs avatar nitin88 avatar

Watchers

 avatar

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.