Skip to content

Instantly share code, notes, and snippets.

@ap0llo
Last active August 6, 2019 16:00
Show Gist options
  • Save ap0llo/4e3b173afe6ca23299add223396de165 to your computer and use it in GitHub Desktop.
Save ap0llo/4e3b173afe6ca23299add223396de165 to your computer and use it in GitHub Desktop.
# https://gist.github.com/ap0llo/4e3b173afe6ca23299add223396de165
function Open-SolutionFile([string]$Name) {
if (($null -ne $Name) -and ($Name -ne "")) {
$slnFiles = Get-ChildItem -File *.sln -Recurse | Where-Object { $_.Name -like "*$Name*" }
} else {
$slnFiles = Get-ChildItem -File *.sln -Recurse
}
$count = ($slnFiles | Measure-Object).Count
if ($count -eq 0) {
throw "No solution files found"
}
elseif ($count -eq 1) {
Start-Process $slnFiles.FullName
}
else {
Write-Host " "
$i = 0
foreach ($file in $slnFiles) {
Write-Host " $i - $($file.Name)"
$i = $i + 1
}
Write-Host " A - Open all solutions"
Write-Host " "
while ($true) {
$selection = Read-Host "Enter id of solution to open"
if ($selection -like "A") {
foreach ($item in $slnFiles) {
Start-Process $item.FullName
}
}
else {
$index = $selection -as [int]
if (($null -ne $index) -and ($index -lt $count) -and ($index -ge 0)) {
Start-Process ($slnFiles[$index]).FullName
break
}
else {
Write-Error "Invalid input '$selection' "
}
}
}
}
}
Set-Alias sln Open-SolutionFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment