-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter.ps1
More file actions
40 lines (35 loc) · 1.12 KB
/
filter.ps1
File metadata and controls
40 lines (35 loc) · 1.12 KB
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
# Rainer Schuster (http://github.com/schuster-rainer/posh-spice)
filter highlight{
param(
[string]$pattern=$(throw "regular expression required"),
[string]$property,
[string]$foreground="red",
[string]$background
)
$default_foreground = [console]::ForegroundColor;
#$default_backgroundcolor = [console]::BackgroundColor;
if( $background -eq $FALSE) {
$background = $default_backgroundcolor
}
$matched = $FALSE
if( $prop -eq $TRUE) {
if($_.$property -match $regex) {
$matched = $TRUE
}
} else {
if($_ -match $pattern) {
$matched = $TRUE
}
}
if( $matched -eq $TRUE) {
[console]::ForegroundColor = $foreground;
#[console]::BackgroundColor = $background;
$_
} else {
[console]::ForegroundColor = $default_foreground;
#[console]::BackgroundColor = $default_background;
$_
}
[console]::ForegroundColor = $default_foreground;
#[console]::BackgroundColor = $default_background;
}