Comments (3)
Hi -
This looks interesting. I only tried the second example from the link you provided. It does not work if you use it like this:
Get-ChildItemColor | Select-Object Name, @{Name="Size";Expression={Format-FileSize($_.Length)}}
because Get-ChildItemColor
just changes $Host.UI.RawUI.ForegroundColor
right before printing an item, and the pipe will not get the color information.
However, if you do the following:
Function Format-FileSize() {
Param ([int]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
Else {""}
}
$Host.UI.RawUI.ForegroundColor = "Red"
Get-ChildItem | Select-Object Name, @{Name="Size";Expression={Format-FileSize($_.Length)}}
You will see that everything is red now, so one way to do this is creating a function which incorporates the coloring as well as Select-Object Name, @{Name="Size";Expression={Format-FileSize($_.Length)}}
part.
Unfortunately I don't have time to implement this at the moment, but I would be happy to accept a PR if you want to open one. I'm sorry!
from get-childitemcolor.
Hi,
thanks for you reply :) I'm afraid I'm not very capable when it comes to more complex PowerShell stuff - maybe I'll to get it working if I find the time. Cheers, Jan
from get-childitemcolor.
Hi,
I just incorporated PSColor's implementation, and this should be working now.
from get-childitemcolor.
Related Issues (20)
- Display issue with Chinese HOT 8
- Fails inside OneDrive HOT 3
- Add option to remove the listing of the path HOT 2
- Is it possible to get an `ll` equivalent? HOT 4
- Out-Default function breaks $? HOT 7
- Cannot bind parameter 'ForegroundColor'. Cannot convert value "" to type "System.ConsoleColor". HOT 2
- incorrect spacing after first launch HOT 2
- Feature Req: Show trailing slash for directory names in wide format view HOT 4
- ls command failed for special marks: Sort-Object and InvalidArgument errors HOT 3
- [req] Diferent colors for hard and softlinks plz (especialyhardlinks) HOT 1
- How to customize the color and save it for next use? HOT 2
- Directory and column descriptions only show up on first launch HOT 4
- Previous command error status is discarded HOT 1
- Unicode char in filename causes UInt32 error HOT 1
- Version 2.2.1 not uploaded to PowerShell Gallery HOT 1
- How to support other file extensions like Office files extensions .pptx, .docx, .xlsx? HOT 4
- Unable to find type [uint] on Windows PowerShell 5 HOT 1
- Length-format differs HOT 1
- actual PowerShell have alredy coloring itself HOT 1
- Fails when used in conjunction with the New-Junction command in PSCX
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from get-childitemcolor.