forked from springcomp/powershell_profile.ps1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoft.PowerShell_git-profile.ps1
177 lines (162 loc) · 5.11 KB
/
Microsoft.PowerShell_git-profile.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# 1.0.7979.15913
[CmdletBinding()]
param( [switch]$completions )
if ($completions.IsPresent) {
Write-Host "Loading CLI completions for git." -ForegroundColor Cyan
## CLI completions require Git bash
$__GIT_HOME=Join-Path -Path (Split-Path (Split-Path -Path (Get-Command "git").Source)) -ChildPath "bin"
$__GIT_HOME | Add-DirectoryToPath -Prepend
Function Has-Module {
param([string]$name)
return [bool] (Get-Module -ListAvailable -Name $name)
}
Function Install-GitCompletion {
[CmdletBinding()]
param([Alias("CompletionsPath")][string]$path)
Install-Module -Name PSBashCompletions -Scope CurrentUser -Force
New-Item -Path $path -ItemType Directory -EA SilentlyContinue | Out-Null
$completions = "https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash"
Invoke-WebRequest -Method Get $completions -OutFile $path/git.sh
}
$completionsPath = Join-Path (Split-Path -Parent $PROFILE) Completions
if ((-not (Has-Module PSBashCompletions)) -or (-not (Test-Path $completionsPath/git.sh))) {
Install-GitCompletion -Completions $completionsPath
}
if (Test-Path $completionsPath) {
if (Get-Module -Name PSBashCompletions -ListAvailable){
Import-Module -Name PSBashCompletions
Register-BashArgumentCompleter git "$completionsPath/git.sh"
}
}
}
Function add { git add $args }
Function amend { git commit --amend $args }
Function append { git commit --amend --no-edit $args }
Function clone { git clone --recurse-submodules $args }
Function commit { git commit $args }
Function feature {
param(
[string]$feature
)
if ($feature.Length -gt 0) {
if ($feature -eq "publish") { & feature-publish }
if ($feature -eq "finish") { & feature-finish }
else { feature-start -feature $feature }
}
else {
$branch = $(git rev-parse --abbrev-ref HEAD)
$feature = $branch.Replace("feature/", "")
Write-Output $feature
}
}
Function feature-start {
param(
[string]$feature
)
git flow feature start $feature
}
Function feature-publish {
$branch = $(git rev-parse --abbrev-ref HEAD)
$feature = $branch.Replace("feature/", "")
git flow feature publish $feature
}
Function feature-finish {
$branch = $(git rev-parse --abbrev-ref HEAD)
$feature = $branch.Replace("feature/", "")
git flow feature finish $feature
}
Function fetch { git fetch --all -p $args }
Function g { git status }
Function lol { git log --oneline --decorate --graph $args }
Function pull { git fetch -p; git merge --ff-only }
Function push { git push $args }
Function pushup {
param(
[string]$remote = "origin",
[switch]$force
)
$branch = $(git rev-parse --abbrev-ref HEAD)
if ($force.IsPresent) {
git push --set-upstream $remote $branch --force
}
else {
git push --set-upstream $remote $branch
}
}
Function release-start {
param(
[string]$release
)
git flow release start $release
}
Function release-publish {
$branch = $(git rev-parse --abbrev-ref HEAD)
$release = $branch.Replace("release/", "")
git flow release publish $release
}
Function release-finish {
$branch = $(git rev-parse --abbrev-ref HEAD)
$release = $branch.Replace("release/", "")
git flow release finish $release
}
## Usage: `remote`: displays the current remote endpoint.
## Usage: `remote <path>`: displays the remote endpoint to a given local git repository
## Usage: `remote $args`: runs `git remote $args`
Function remote {
if (($args.Length -eq 1) -and (Test-Path -Path $args[0])){
$path = $args[0]
pushd $path; iex ". remote"; popd
return
}
if (-not $args) {
git remote -v |? { $_ -match "(fetch)" } |`
Select-Object -First 1 |% {
$_ -replace "^(?<remote>[^\t\ ]+)\t+(?<uri>[^\ ]+)\ \(fetch\)`$", "`$2"
}
} else {
git remote $args
}
}
Function reset {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[Alias("FullName")]
[string]$path
)
PROCESS {
git checkout HEAD -- $path
}
}
Function undo_redo {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[Alias("FullName")]
[string]$path,
[string]$comment = "undo"
)
PROCESS {
git checkout HEAD^1 -- "$path"
git add $path
git commit -m "$($comment): $($path)"
}
}
Function undo {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[Alias("FullName")]
[string]$path
)
PROCESS { undo_redo -path $path }
}
Function redo {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[Alias("FullName")]
[string]$path
)
PROCESS { undo_redo -path $path -comment "redo" }
}