-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMake-Show-Tree-Look-Like-Tree.ps1
72 lines (64 loc) · 1.63 KB
/
Make-Show-Tree-Look-Like-Tree.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
60
61
62
63
64
65
66
67
68
69
70
71
72
$newItemSplat = @{
ItemType = 'Directory'
Path = $PSScriptRoot
Name = '.output'
# Force = $true
}
New-Item @newItemSplat -ea Ignore
& {
# a list of literals, not patterns, to replace
$CachedOutput = @'
+--AngleSharp
| \--AngleSharp
| +--.github
| | +--ISSUE_TEMPLATE
| | \--workflows
| +--docs
| | +--general
| | \--tutorials
| +--src
| | +--AngleSharp
| | +--AngleSharp.Benchmarks
| | +--AngleSharp.Core.Docs
| | +--AngleSharp.Core.Tests
| | \--TestGeneration
| \--tools
\--kamome283
\--AngleParse
+--AngleParse
| +--Resource
| \--Selector
+--AngleParse.Test
| +--Resource
| \--Selector
\--build
'@
$Replacements | ConvertTo-Json
$Replacements = @(
, ('-', '─')
, ('\', '└')
, ('-', '─')
, ('|', '│')
, ('+', '├')
)
PSScriptTools\Show-Tree c:\programs -Depth 3
| Join-String -sep "`n" | ForEach-Object {
$accum = $_
foreach ($pair in $Replacements) {
$pattern = [regex]::Escape( $pair[0] )
$replace = $pair[1]
$accum = $accum -replace $pattern, $replace
}
$accum
}
h1 'Original (cached)'
# $CachedOutput
h1 'Replacement mapping'
, $Replacements | Join-String -sep "`n" {
'{0} ⇒ {1}' -f @(
$_[0] | New-Text -fg red | ForEach-Object tostring
$_[1] | New-Text -fg green | ForEach-Object tostring
)
}
} | Out-String | Out-File -FilePath './.output/show-tree.ansi' -Encoding utf8 -Force
# todo: it's stripping ansi