Last active
August 16, 2021 18:06
-
-
Save ljtill/449fb3c27e8a8f830f640f4f8dddad7b to your computer and use it in GitHub Desktop.
Provides the ability to list Git branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Get-GitBranch { | |
| [CmdletBinding()] | |
| param ( | |
| ) | |
| begin { | |
| $branch = Invoke-Expression -Command "git branch --all" | |
| $current = @() | |
| $local = @() | |
| $remote = @() | |
| } | |
| process { | |
| switch -Regex ($branch) { | |
| "^(?<current>(\*).*)" { | |
| # Current | |
| $current += $matches["current"] | |
| } | |
| "^(?<local>(\s|\*).(?!remotes).*)" { | |
| # Local | |
| $local += $matches["local"] | |
| } | |
| "^(?<remote>(\s).(remotes).*)" { | |
| # Remote | |
| $remote += $matches["remote"] | |
| } | |
| } | |
| $branch = [PSCustomObject] @{ | |
| Current = $current | |
| Local = $local | |
| Remote = $remote | |
| } | |
| } | |
| end { | |
| return $branch | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment