3
3
# https://github.com/joonro/Get-ChildItem-Color
4
4
# Add from https://github.com/JRJurman/PowerLS/blob/master/powerls.psm1
5
5
# ##############################################################################
6
- function Get-ChildItem-Color {
7
- if ($Args [0 ] -eq $true ) {
8
- $ifwide = $true
9
-
10
- if ($Args.Length -gt 1 ) {
11
- $Args = $Args [1 .. ($Args.length - 1 )]
12
- } else {
13
- $Args = @ ()
14
- }
15
- } else {
16
- $ifwide = $false
17
- }
18
-
19
- if (($Args [0 ] -eq " -a" ) -or ($Args [0 ] -eq " --all" )) {
20
- $Args [0 ] = " -Force"
21
- }
6
+ function Get-ChildItem-Wide {
22
7
23
8
$width = $host.UI.RawUI.WindowSize.Width
24
- $color_fore = $host.UI.RawUI.ForegroundColor
25
-
26
- $compressed_list = @ (" .zip" , " .tar" , " .gz" , " .rar" )
27
- $executable_list = @ (" .exe" , " .bat" , " .cmd" , " .py" , " .pl" , " .ps1" ,
28
- " .psm1" , " .vbs" , " .rb" , " .reg" , " .fsx" , " .sh" )
29
- $dll_pdb_list = @ (" .dll" , " .pdb" )
30
- $text_files_list = @ (" .txt" , " .csv" , " .lg" , " .log" , " .packer" , " .json" , " .md" , " .pp" , " .markdown" )
31
- $configs_list = @ (" .cfg" , " .config" , " .conf" , " .ini" , " .properties" , " .gradle" , " .gitignore" , " .gitattributes" )
32
-
33
- $color_table = @ {}
34
- foreach ($Extension in $compressed_list ) {
35
- $color_table [$Extension ] = " Yellow"
36
- }
37
-
38
- foreach ($Extension in $executable_list ) {
39
- $color_table [$Extension ] = " Blue"
40
- }
41
-
42
- foreach ($Extension in $text_files_list ) {
43
- $color_table [$Extension ] = " Cyan"
44
- }
45
-
46
- foreach ($Extension in $dll_pdb_list ) {
47
- $color_table [$Extension ] = " Darkgreen"
48
- }
49
-
50
- foreach ($Extension in $configs_list ) {
51
- $color_table [$Extension ] = " Yellow"
52
- }
53
-
54
- # Handle hiddne files
55
- $hidden_files = " ^\..*$"
56
- $color_table [" hidden_files" ] = " DarkGray"
57
-
58
- $i = 0
59
- $pad = 4
9
+ $pad = 2
60
10
61
11
# get the longest string and get the length
62
12
$childs = Get-ChildItem $Args
@@ -65,65 +15,16 @@ function Get-ChildItem-Color {
65
15
66
16
$childs |
67
17
ForEach-Object {
68
- if ($_.GetType ().Name -eq ' DirectoryInfo' ) {
69
- $c = ' Green'
70
- } elseif ($_.Name -match $hidden_files ) {
71
- $c = $color_table [" hidden_files" ]
72
- } else {
73
- $c = $color_table [$_.Extension ]
74
-
75
- if ($c -eq $none ) {
76
- $c = $color_fore
77
- }
78
- }
79
-
80
- if ($ifwide ) {
81
- if ($i -eq -1 ) { # change this to `-eq 0` to show DirectoryName
82
- if ($_.GetType ().Name -eq " FileInfo" ) {
83
- $DirectoryName = $_.DirectoryName
84
- } elseif ($_.GetType ().Name -eq " DirectoryInfo" ) {
85
- $DirectoryName = $_.Parent.FullName
86
- }
87
- Write-Host " "
88
- Write-Host - Fore ' Green' (" Directory: " + $DirectoryName )
89
- Write-Host " "
90
- }
91
- $towrite = $_.Name + (" " * ($len - $_.name.length + $pad ))
92
- $count += $towrite.length
93
-
94
- Write-Host $towrite - Fore $c - nonewline
18
+ $output = $_.name + (" " * ($len - $_.name.length + $pad ))
19
+ $count += $output.length
95
20
96
- if ( $count -ge ($width - ($len + $pad )) ) {
97
- Write-Host " "
98
- $count = 0
99
- }
100
- } else {
101
- If ($i -eq 0 ) { # first item - print out the header
102
- Write-Host " `n Directory: $DirectoryName `n "
103
- Write-Host " Mode LastWriteTime Length Name"
104
- Write-Host " ---- ------------- ------ ----"
105
- }
106
- $Host.UI.RawUI.ForegroundColor = $c
107
-
108
- Write-Host (" {0,-7} {1,25} {2,10} {3}" -f $_.mode ,
109
- ([String ]::Format(" {0,10} {1,8}" ,
110
- $_.LastWriteTime.ToString (" d" ),
111
- $_.LastWriteTime.ToString (" t" ))),
112
- $length , $_.name )
113
-
114
- $Host.UI.RawUI.ForegroundColor = $color_fore
115
-
116
- ++ $i # increase the counter
117
- }
118
- }
119
- Write-Host " "
120
- }
21
+ Write-Host $output - nonewline
121
22
122
- function Get-ChildItem-Format-Wide {
123
- $New_Args = @ ($true )
124
- $New_Args += $Args
125
- Get-ChildItem - Color $New_Args
23
+ if ( $count -ge ($width - ($len + $pad )) ) {
24
+ Write-Host " "
25
+ $count = 0
26
+ }
27
+ }
126
28
}
127
29
128
- Set-Alias - Name ll - Value Get-ChildItem - Color - option AllScope - Scope Global
129
- Set-Alias - Name ls - Value Get-ChildItem - Format-Wide - option AllScope - Scope Global
30
+ Set-Alias - Name ls - Value Get-ChildItem - Wide - option AllScope - Scope Global
0 commit comments