-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls.ps1
59 lines (50 loc) · 1.39 KB
/
ls.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function Show-FilesUnixStyle {
<#
.SYNOPSIS
Lists directory contents with color-coding.
.DESCRIPTION
This function lists directory contents with color-coding for different item types.
It vaguely mimics the behavior of Unix 'ls' command.
.PARAMETER Path
Specifies the path to list. If not provided, it uses the current directory.
.PARAMETER IncludeHidden
Include hidden files and directories in the listing.
.EXAMPLE
Show-FilesUnixStyle
.EXAMPLE
Show-FilesUnixStyle -Path C:\Users -IncludeHidden
#>
param (
[Parameter(Position = 0, ValueFromPipeline = $true)]
[string[]]$Path = (Get-Location).Path,
[Alias("a")]
[switch]$IncludeHidden
)
Get-ChildItem -Path "$Path" -Force | ForEach-Object {
if ($_.Attributes -band [System.IO.FileAttributes]::Hidden) {
if (!$IncludeHidden) {
return
}
$name = With-Black $_.Name
}
elseif ($_.Attributes -band [System.IO.FileAttributes]::System) {
$name = With-Red $_.Name
}
elseif ($_.Attributes -band [System.IO.FileAttributes]::ReparsePoint) {
$name = ((With-Blue $_.Name) + " → " + (Get-Item $_.FullName).Target)
}
elseif ($_ -is [System.IO.DirectoryInfo]) {
$name = With-Yellow $_.Name
}
elseif ($_ -is [System.IO.FileInfo]) {
$name = With-Cyan $_.Name
}
else {
$name = $_.Name
}
if ($_ -is [System.IO.DirectoryInfo]) {
$name += "/"
}
$name
}
}