Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 201 lines (168 sloc) 6.474 kB
3033fa5 @dahlbyk Rough start
authored
1 # Initial implementation by Jeremy Skinner
2 # http://www.jeremyskinner.co.uk/2010/03/07/using-git-with-windows-powershell/
3
6daf5c8 @dahlbyk Add GitTabSettings
authored
4 $global:GitTabSettings = New-Object PSObject -Property @{
5 AllCommands = $false
6 }
7
9ecab15 @dahlbyk Operation completion for remote and stash
authored
8 $global:ops = @{
9 remote = 'add','rename','rm','set-head','show','prune','update'
10 stash = 'list','show','drop','pop','apply','branch','save','clear','create'
cf77202 @dahlbyk Fix whitespace
authored
11 svn = 'init', 'fetch', 'clone', 'rebase', 'dcommit', 'branch', 'tag', 'log', 'blame', 'find-rev', 'set-tree', 'create-ignore', 'show-ignore', 'mkdirs', 'commit-diff', 'info', 'proplist', 'propget', 'show-externals', 'gc', 'reset'
9ecab15 @dahlbyk Operation completion for remote and stash
authored
12 }
13
14 function script:gitCmdOperations($command, $filter) {
15 $ops.$command |
16 where { $_ -like "$filter*" }
17 }
18
6daf5c8 @dahlbyk Add GitTabSettings
authored
19 function script:gitCommands($filter, $includeAliases) {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
20 $cmdList = @()
6daf5c8 @dahlbyk Add GitTabSettings
authored
21 if (-not $global:GitTabSettings.AllCommands) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
22 $cmdList += git help |
23 foreach { if($_ -match '^ (\S+) (.*)') { $matches[1] } } |
24 where { $_ -like "$filter*" }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
25 } else {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
26 $cmdList += git help --all |
27 where { $_ -match '^ \S.*' } |
28 foreach { $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) } |
29 where { $_ -like "$filter*" }
3033fa5 @dahlbyk Rough start
authored
30 }
cf77202 @dahlbyk Fix whitespace
authored
31
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
32 if ($includeAliases) {
33 $cmdList += gitAliases $filter
34 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
35 $cmdList | sort
3033fa5 @dahlbyk Rough start
authored
36 }
37
38 function script:gitRemotes($filter) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
39 git remote |
40 where { $_ -like "$filter*" }
3033fa5 @dahlbyk Rough start
authored
41 }
cf77202 @dahlbyk Fix whitespace
authored
42
58bf2a7 @dahlbyk Add expansion for git reset <commit>
authored
43 function script:gitLocalBranches($filter, $includeHEAD = $false) {
44 $branches = git branch |
45 foreach { if($_ -match "^\*?\s*(.*)") { $matches[1] } }
46
47 @(if ($includeHEAD) { 'HEAD' }) + @($branches) |
48 where { $_ -ne '(no branch)' -and $_ -like "$filter*" }
3033fa5 @dahlbyk Rough start
authored
49 }
50
8c526cb Stash completion
unknown authored
51 function script:gitStashes($filter) {
52 (git stash list) -replace ':.*','' |
53 where { $_ -like "$filter*" } |
54 foreach { "'$_'" }
55 }
56
3033fa5 @dahlbyk Rough start
authored
57 function script:gitIndex($filter) {
58 if($GitStatus) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
59 $GitStatus.Index |
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
60 where { $_ -like "$filter*" } |
61 foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
3033fa5 @dahlbyk Rough start
authored
62 }
63 }
64
65 function script:gitFiles($filter) {
66 if($GitStatus) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
67 $GitStatus.Working |
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
68 where { $_ -like "$filter*" } |
69 foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
3033fa5 @dahlbyk Rough start
authored
70 }
71 }
72
223c61a @dahlbyk Complete 'git rm' with files deleted from working tree
authored
73 function script:gitDeleted($filter) {
74 if($GitStatus) {
290c601 @dahlbyk Add tab expansion for 'git rm' during deleted/updated merge conflict
authored
75 @($GitStatus.Working.Deleted) + @($GitStatus.Index.Deleted) |
223c61a @dahlbyk Complete 'git rm' with files deleted from working tree
authored
76 where { $_ -like "$filter*" } |
77 foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
78 }
79 }
80
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
81 function script:gitAliases($filter) {
5ed95ee @dahlbyk Refactor gitAliases
authored
82 git config --get-regexp ^alias\. | foreach {
83 if($_ -match "^alias\.(?<alias>\S+) .*") {
84 $alias = $Matches['alias']
85 if($alias -like "$filter*") {
86 $alias
87 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
88 }
5ed95ee @dahlbyk Refactor gitAliases
authored
89 } | Sort
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
90 }
91
ed18e09 @dahlbyk Support tab expansion for commands behind simple git aliases
authored
92 function script:expandGitAlias($cmd, $rest) {
93 if((git config --get-regexp "^alias\.$cmd`$") -match "^alias\.$cmd (?<cmd>[^!]\S+) .*`$") {
94 return "git $($Matches['cmd'])$rest"
95 } else {
96 return "git $cmd$rest"
97 }
98 }
99
133fba1 @dahlbyk Revert "Adjust function scoping"
authored
100 function GitTabExpansion($lastBlock) {
ed18e09 @dahlbyk Support tab expansion for commands behind simple git aliases
authored
101 if($lastBlock -match '^git (?<cmd>\S+)(?<args> .*)$') {
102 $lastBlock = expandGitAlias $Matches['cmd'] $Matches['args']
103 }
104
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
105 switch -regex ($lastBlock) {
2eb6bb0 @JeremySkinner Add support for TortoiseGit tab expansion
JeremySkinner authored
106
107 # Handles tgit <command> (tortoisegit)
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
108 '^tgit (\S*)$' {
2eb6bb0 @JeremySkinner Add support for TortoiseGit tab expansion
JeremySkinner authored
109 # Need return statement to prevent fall-through.
110 return $tortoiseGitCommands | where { $_ -like "$($matches[1])*" }
111 }
cf77202 @dahlbyk Fix whitespace
authored
112
9ecab15 @dahlbyk Operation completion for remote and stash
authored
113 # Handles git remote <op>
114 # Handles git stash <op>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
115 '^git (?<cmd>remote|stash|svn) (?<op>\S*)$' {
116 gitCmdOperations $matches['cmd'] $matches['op']
9ecab15 @dahlbyk Operation completion for remote and stash
authored
117 }
8c526cb Stash completion
unknown authored
118
3087b5e @dahlbyk Remote name completion for git fetch and relevant git remote operations
authored
119 # Handles git remote (rename|rm|set-head|set-branches|set-url|show|prune) <stash>
120 '^git remote.* (?:rename|rm|set-head|set-branches|set-url|show|prune).* (?<remote>\S*)$' {
121 gitRemotes $matches['remote']
122 }
123
8c526cb Stash completion
unknown authored
124 # Handles git stash (show|apply|drop|pop|branch) <stash>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
125 '^git stash (?:show|apply|drop|pop|branch).* (?<stash>\S*)$' {
126 gitStashes $matches['stash']
8c526cb Stash completion
unknown authored
127 }
cf77202 @dahlbyk Fix whitespace
authored
128
d1a35c5 @dahlbyk Tab completion for branch rename
authored
129 # Handles git branch -d|-D|-m|-M <branch name>
223c61a @dahlbyk Complete 'git rm' with files deleted from working tree
authored
130 # Handles git branch <branch name> <start-point>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
131 '^git branch.* (?<branch>\S*)$' {
132 gitLocalBranches $matches['branch']
3033fa5 @dahlbyk Rough start
authored
133 }
cf77202 @dahlbyk Fix whitespace
authored
134
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
135 # Handles git <cmd> (commands & aliases)
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
136 '^git (?<cmd>\S*)$' {
137 gitCommands $matches['cmd'] $TRUE
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
138 }
cf77202 @dahlbyk Fix whitespace
authored
139
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
140 # Handles git help <cmd> (commands only)
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
141 '^git help (?<cmd>\S*)$' {
142 gitCommands $matches['cmd'] $FALSE
3033fa5 @dahlbyk Rough start
authored
143 }
cf77202 @dahlbyk Fix whitespace
authored
144
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
145 # Handles git push remote <branch>
146 # Handles git pull remote <branch>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
147 '^git (?:push|pull).* (?:\S+) (?<branch>\S*)$' {
148 gitLocalBranches $matches['branch']
3033fa5 @dahlbyk Rough start
authored
149 }
cf77202 @dahlbyk Fix whitespace
authored
150
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
151 # Handles git pull <remote>
152 # Handles git push <remote>
3087b5e @dahlbyk Remote name completion for git fetch and relevant git remote operations
authored
153 # Handles git fetch <remote>
154 '^git (?:push|pull|fetch).* (?<remote>\S*)$' {
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
155 gitRemotes $matches['remote']
3033fa5 @dahlbyk Rough start
authored
156 }
157
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
158 # Handles git reset HEAD <path>
894c0c4 @dahlbyk Make tab expansion less picky about when it will expand; clean up reg…
authored
159 # Handles git reset HEAD -- <path>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
160 '^git reset.* HEAD(?:\s+--)? (?<path>\S*)$' {
161 gitIndex $matches['path']
3033fa5 @dahlbyk Rough start
authored
162 }
163
21d8bf9 @dahlbyk Local branch completion for cherry-pick and log
authored
164 # Handles git cherry-pick <commit>
9343ceb @dahlbyk Add branch expansion for diff and show
authored
165 # Handles git diff <commit>
341e65e @dahlbyk Add branch expansion for difftool
authored
166 # Handles git difftool <commit>
21d8bf9 @dahlbyk Local branch completion for cherry-pick and log
authored
167 # Handles git log <commit>
9343ceb @dahlbyk Add branch expansion for diff and show
authored
168 # Handles git show <commit>
341e65e @dahlbyk Add branch expansion for difftool
authored
169 '^git (?:cherry-pick|diff|difftool|log|show).* (?<commit>\S*)$' {
21d8bf9 @dahlbyk Local branch completion for cherry-pick and log
authored
170 gitLocalBranches $matches['commit']
171 }
172
58bf2a7 @dahlbyk Add expansion for git reset <commit>
authored
173 # Handles git reset <commit>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
174 '^git reset.* (?<commit>\S*)$' {
175 gitLocalBranches $matches['commit'] $true
58bf2a7 @dahlbyk Add expansion for git reset <commit>
authored
176 }
177
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
178 # Handles git add <path>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
179 '^git add.* (?<files>\S*)$' {
180 gitFiles $matches['files']
3033fa5 @dahlbyk Rough start
authored
181 }
c7511ea @dahlbyk Path completion for 'git checkout -- <tab>'
authored
182
183 # Handles git checkout -- <path>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
184 '^git checkout.* -- (?<files>\S*)$' {
185 gitFiles $matches['files']
c7511ea @dahlbyk Path completion for 'git checkout -- <tab>'
authored
186 }
894c0c4 @dahlbyk Make tab expansion less picky about when it will expand; clean up reg…
authored
187
188 # Handles git rm <path>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
189 '^git rm.* (?<index>\S*)$' {
190 gitDeleted $matches['index']
894c0c4 @dahlbyk Make tab expansion less picky about when it will expand; clean up reg…
authored
191 }
192
193 # Handles git checkout <branch name>
194 # Handles git merge <branch name>
195 # handles git rebase <branch name>
2b3269f @dahlbyk Update tab expansion regex to use named capture
authored
196 '^git (?:checkout|merge|rebase).* (?<branch>\S*)$' {
197 gitLocalBranches $matches['branch']
894c0c4 @dahlbyk Make tab expansion less picky about when it will expand; clean up reg…
authored
198 }
8c526cb Stash completion
unknown authored
199 }
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
200 }
Something went wrong with that request. Please try again.