-
Notifications
You must be signed in to change notification settings - Fork 0
/
proj.ps1
96 lines (69 loc) · 1.85 KB
/
proj.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
param([int]$Depth = 3, $Pattern = $null, $Type = "sln")
function FindParentContainingGitRepository {
param($Item)
$gitDirectories = Get-ChildItem -Force -Path $Item.FullName -Directory | Where-Object {$_.Name -eq ".git"}
if($gitDirectories.Count -gt 0) {
return $Item.Name
}
if($Item.FullName -eq $Item.Root.FullName) {
return ""
}
FindParentContainingGitRepository -Item $item.Parent
}
function Main
{
$slnFiles = Get-ChildItem -Path .\ -Filter "*.$Type" -Recurse -Depth $Depth
if($pattern -ne $null) {
$slnFiles = $slnFiles | Where-Object { $_.Name | Select-String -Pattern $pattern -SimpleMatch }
}
if($slnFiles.Count -eq 0) {
Write-Error 'Could not locate any sln files'
return $null
}
if($slnFiles.Count -eq 1) {
return ($slnFiles | Select-Object -first 1).FullName
}
$i = 0;
Write-Host
Write-Host 'Select a sln file to open'
Write-Host
Foreach($sln in $slnFiles) {
$iStr = $i.ToString().PadLeft(2)
$parent = FindParentContainingGitRepository -Item $sln.Directory
Write-Host "[$iStr] ".PadRight(4) -NoNewline
$padding = 60
if($parent -ne "") {
Write-Host "$parent" -NoNewline -Foreground red
Write-Host "\" -NoNewline
$padding -= $parent.Length
}
$output = "$sln".PadRight($padding) + "`t"
Write-Host "$output" -NoNewline -Foreground green
$i++
if(($i % 2) -eq 0) {
Write-Host
}
}
Write-Host
Write-Host "[Q] Quit"
Write-Host
Write-Host "Selection: " -NoNewline
$validSelection = $false
$sel = -1
do {
$selected = Read-Host
if($selected -eq 'q' -or $selected -eq 'Q') {
return
}
$sel = -1
if(-not([int]::TryParse($selected, [ref]$sel)) -or
($sel -lt 0 -or $sel -ge $slnFiles.Count)) {
Write-Host "Invalid input"
Write-Host "input: " -NoNewline
continue
}
$validSelection = $true
}while($validSelection -ne $true)
return $slnFiles[$sel].FullName
}
Main