Skip to content

Commit 9d43ab9

Browse files
committed
Merge branch 'release/v3.0.0'
2 parents 8f91d52 + 572f44b commit 9d43ab9

File tree

3 files changed

+52
-44
lines changed

3 files changed

+52
-44
lines changed

README.org

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@ by [[http://thepowershellguy.com/][the PowerShell Guy]], and [[https://github.co
88

99
It provides two main functionalities:
1010

11-
1. Directly provide coloring of ~Get-ChildItem~ output by modifying
12-
~Out-Default~. Once the module is imported, ~Get-ChildItem~'s output will
13-
be automatically colored. It does support pipeline (e.g., ~Get-ChildItem |
14-
grep ".git"~). Also, now the directory name and the headers of its output
15-
have consistent colors. This is an adaptation of [[https://github.com/Davlind/PSColor][PSColor]].
11+
1. Provide ~Get-ChildItemColor~, which adds coloring to the output of
12+
~Get-ChildItem~, this function supports pipelines (it is pipeline-aware, so
13+
it does not touch the output when it is being used in a pipeline).
1614
2. It provides =Get-ChildItemColorFormatWide=, which uses =Write-Host= to
1715
output coloring. This is because =Get-ChildItemColor | Format-Wide= does
18-
not allow multiple colors in one line. As a result, pipeline does not work with
19-
=Get-ChildItemColorFormatWide=.
16+
not allow multiple colors in one line. As a result, pipeline does not work
17+
with =Get-ChildItemColorFormatWide=.
2018

21-
It also provides ~Get-ChildItemColor~, which just changes
22-
=$Host.UI.RawUI.ForegroundColor= and keep the item object intact. This was the
23-
implementation before v2.0.0, and it does support pipeline. (e.g.,
24-
~Get-ChildItemColor | grep ".git"~). The main shortcoming of this approach is
25-
that the directory name and the headers of its output have inconsistent
26-
colors.
19+
Note that as of v3.0.0, it no longer overloads ~Out-Default~, and thus ~Get-ChildItem~'s
20+
output will not be touched. Users should use ~Get-ChildItemColor~ instead.
2721

2822
* Screenshot:
2923
** Get-ChildItem (Colorized)
@@ -54,10 +48,8 @@ When you import the module:
5448
Import-Module Get-ChildItemColor
5549
#+end_src
5650

57-
it provides a proxy function for =Output-Default=, so =Get-ChildItem='s output
58-
will be automatically colored. In addition, it provides two functions,
59-
=Get-ChildItemColorFormatWide= and =Get-ChildItemColor= (the latter is
60-
unlikely to be useful, but remained intact just in case).
51+
it provides two functions, =Get-ChildItemColorFormatWide= and
52+
=Get-ChildItemColor=.
6153

6254
You can add aliases to these functions for convenience. For example, I have
6355
the following in my profile[fn:pathProfile] (please do not put this into ISE
@@ -67,15 +59,18 @@ profile[fn:pathProfileISE] as it does not work in ISE):
6759
If (-Not (Test-Path Variable:PSise)) { # Only run this in the console and not in the ISE
6860
Import-Module Get-ChildItemColor
6961

70-
Set-Alias l Get-ChildItem -option AllScope
71-
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope [-HideHeader]
62+
Set-Alias l Get-ChildItemColor -option AllScope
63+
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope [-HideHeader] [-TrailingSlashDirectory]
7264
}
7365
#+end_src
7466

7567
So =l= yields colored output of =Get-ChildItem= and =ls= yields colored output
76-
of =Get-ChildItem | Format-Wide= equivalent. There is an optional
77-
~-HideHeader~ switch which will supress printing of headers (path on top) for
78-
~Get-ChildItemColorFormatWide~ when specified.
68+
of =Get-ChildItem | Format-Wide= equivalent.
69+
70+
~Get-ChildItemColorFormatWide~ has the following optional switches:
71+
72+
- -HideHeader :: supress printing of headers (path on top).
73+
- -TrailingSlashDirectory :: add a trailing slash to directory names.
7974

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

@@ -118,6 +113,10 @@ $Global:GetChildItemColorVerticalSpace = 1
118113
* Authors
119114
- [[http://github.com/joonro][Joon Ro]].
120115
* Changelog
116+
** v3.0.0
117+
- ~Get-ChildItemColor~ is pipeline-aware and only adds color when it is not
118+
being used as a part of a pipeline. It no longer overloads ~Out-Default~. ([[https://github.com/joonro/Get-ChildItemColor/issues/31][#31]])
119+
- Add ~TrailingSlashDirectory~ switch to ~Get-ChildItemColorFormatWide~ ([[https://github.com/joonro/Get-ChildItemColor/issues/37][#37]])
121120
** v2.4.0
122121
- Add ~HideHeader~ switch to ~Get-ChildItemColorFormatWide~ ([[https://github.com/joonro/Get-ChildItemColor/issues/29][#29]])
123122
** v2.3.0

src/Get-ChildItemColor.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
RootModule = 'Get-ChildItemColor.psm1'
1111

1212
# Version number of this module.
13-
ModuleVersion = '2.4.0'
13+
ModuleVersion = '3.0.0'
1414

1515
# Supported PSEditions
1616
# CompatiblePSEditions = @()
@@ -70,7 +70,7 @@ Description = 'Get-ChildItemColor provides colored versions of Get-ChildItem Cmd
7070
FunctionsToExport = @(
7171
'Get-ChildItemColor',
7272
'Get-ChildItemColorFormatWide'
73-
'Out-Default'
73+
'Out-ChildItemColor'
7474
)
7575

7676
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

src/Get-ChildItemColor.psm1

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,12 @@ Function Get-FileColor($Item) {
2222
Return $Color
2323
}
2424

25-
Function Get-ChildItemColor {
26-
Param(
27-
[string]$Path = ""
28-
)
29-
$Expression = "Get-ChildItem -Path `"$Path`" $Args"
30-
31-
$Items = Invoke-Expression $Expression
32-
33-
ForEach ($Item in $Items) {
34-
$Color = Get-FileColor $Item
35-
36-
$Host.UI.RawUI.ForegroundColor = $Color
37-
$Item
38-
$Host.UI.RawUI.ForegroundColor = $OriginalForegroundColor
39-
}
40-
}
41-
4225
Function Get-ChildItemColorFormatWide {
4326
Param(
4427
[string]$Path = "",
4528
[switch]$Force,
46-
[switch]$HideHeader
29+
[switch]$HideHeader,
30+
[switch]$TrailingSlashDirectory
4731
)
4832

4933
$nnl = $True
@@ -106,6 +90,11 @@ Function Get-ChildItemColorFormatWide {
10690

10791
# truncate the item name
10892
$toWrite = $Item.Name
93+
94+
If ($TrailingSlashDirectory -and $Item.GetType().Name -eq 'DirectoryInfo') {
95+
$toWrite += '\'
96+
}
97+
10998
$itemLength = LengthInBufferCells($toWrite)
11099
If ($itemLength -gt $pad) {
111100
$toWrite = (CutString $toWrite $pad)
@@ -142,7 +131,7 @@ Add-Type -assemblyname System.ServiceProcess
142131

143132
$Script:ShowHeader=$True
144133

145-
Function Out-Default {
134+
Function Out-ChildItemColor {
146135
[CmdletBinding(HelpUri='http://go.microsoft.com/fwlink/?LinkID=113362', RemotingCapability='None')]
147136
param(
148137
[switch] ${Transcript},
@@ -213,4 +202,24 @@ Function Out-Default {
213202
#>
214203
}
215204

216-
Export-ModuleMember -Function Out-Default, 'Get-*'
205+
Function Get-ChildItemColor {
206+
[CmdletBinding()]
207+
Param(
208+
[string]$Path = ""
209+
)
210+
211+
Begin {
212+
$Expression = "Get-ChildItem -Path `"$Path`" $Args"
213+
$Items = Invoke-Expression $Expression
214+
}
215+
216+
Process {
217+
If ($PSCmdlet.MyInvocation.Line -Match '\|') { # pipeline is used
218+
$Items
219+
} Else {
220+
$Items | Out-ChildItemColor
221+
}
222+
}
223+
}
224+
225+
Export-ModuleMember -Function Out-ChildItemColor, 'Get-*'

0 commit comments

Comments
 (0)