Skip to content

Instantly share code, notes, and snippets.

@steviecoaster
Last active July 8, 2021 01:26
Show Gist options
  • Save steviecoaster/e1458c6f524a9c179c3f40d3d9270588 to your computer and use it in GitHub Desktop.
Save steviecoaster/e1458c6f524a9c179c3f40d3d9270588 to your computer and use it in GitHub Desktop.
Quickly open Git repos on your machine.
Function Open-GitRepo {
<#
.SYNOPSIS
Changes your $pwd to the directory of the requested repo name
.DESCRIPTION
Changes your $pwd to the directory of the requested repo name
.PARAMETER Repo
The repo to open
.EXAMPLE
Open-GitRepo -Repo SuperAwesomeProject
#>
[Alias("Goto")]
[cmdletBinding()]
Param(
[Parameter(Mandatory)]
[ArgumentCompleter(
{
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
$results= Get-ChildItem "$env:HOME\Documents\git\ChocoStuff","$env:HOME\Documents\vagrantenvironments" -Directory | Select-Object -ExpandProperty Name
If ($WordToComplete) {
$results.Where{ $_ -match "^$WordToComplete" }
}
Else {
$results
}
}
)]
[String]
$Repo
)
process {
$path = (Get-ChildItem "$env:HOME\Documents\git\ChocoStuff","$env:HOME\Documents\vagrantenvironments" -Directory | Where-Object { $_.FullName -match "$Repo" }).FullName
Push-Location $path
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment