Skip to content

Instantly share code, notes, and snippets.

@DorukUlucay
Created February 28, 2019 12:19
Show Gist options
  • Save DorukUlucay/4c4672b6f1f2376ae1cfc4e5b0ca5433 to your computer and use it in GitHub Desktop.
Save DorukUlucay/4c4672b6f1f2376ae1cfc4e5b0ca5433 to your computer and use it in GitHub Desktop.
PowerShell
# Get current branches of dirs in a dir
function isAGitDir() {
if ((Test-Path ".git") -eq $TRUE) {
return $TRUE
}
return $FALSE
}
function gitCheck($path) {
$table = New-Object system.Data.DataTable “theTable”
$col1 = New-Object system.Data.DataColumn Directory, ([string])
$col2 = New-Object system.Data.DataColumn Branch, ([string])
$table.columns.add($col1)
$table.columns.add($col2)
if (!$path) {
cd \git
}
else {
cd $path
}
foreach ($dir in ls -directory) {
cd $dir.name
$row = $table.NewRow()
$row.Directory = $dir.name
$isAGitDir = isAGitDir;
if ($isAGitDir) {
$branch = git rev-parse --abbrev-ref HEAD
$row.Branch = $branch
}
else {
$row.Branch = "NOT A GIT DIR"
}
$table.Rows.Add($row)
cd ..
}
cls
$table | format-table -AutoSize
}
ECHO "Retrieving the info..."
gitCheck
Read-Host -Prompt "Press Enter to exit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment