Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 154 lines (128 sloc) 4.687 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'
242138d @JeremySkinner Add support for git svn tab expansion
JeremySkinner 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 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling 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 }
42
43 function script:gitLocalBranches($filter) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
44 git branch |
45 foreach { if($_ -match "^\*?\s*(.*)") { $matches[1] } } |
46 where { $_ -like "$filter*" }
3033fa5 @dahlbyk Rough start
authored
47 }
48
8c526cb Stash completion
unknown authored
49 function script:gitStashes($filter) {
50 (git stash list) -replace ':.*','' |
51 where { $_ -like "$filter*" } |
52 foreach { "'$_'" }
53 }
54
3033fa5 @dahlbyk Rough start
authored
55 function script:gitIndex($filter) {
56 if($GitStatus) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
57 $GitStatus.Index |
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
58 where { $_ -like "$filter*" } |
59 foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
3033fa5 @dahlbyk Rough start
authored
60 }
61 }
62
63 function script:gitFiles($filter) {
64 if($GitStatus) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
65 $GitStatus.Working |
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
66 where { $_ -like "$filter*" } |
67 foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
3033fa5 @dahlbyk Rough start
authored
68 }
69 }
70
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
71 function script:gitAliases($filter) {
72 $aliasList = @()
73 git config --get-regexp alias\..+ | foreach {
74 $alias = $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries)[0].Split(
75 '.', [StringSplitOptions]::RemoveEmptyEntries)[1]
76
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
77 if($alias -like "$filter*") {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
78 $aliasList += $alias.Trim()
79 }
80 }
81 $aliasList | Sort
82 }
83
133fba1 @dahlbyk Revert "Adjust function scoping"
authored
84 function GitTabExpansion($lastBlock) {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
85 switch -regex ($lastBlock) {
2eb6bb0 @JeremySkinner Add support for TortoiseGit tab expansion
JeremySkinner authored
86
87 # Handles tgit <command> (tortoisegit)
88 'tgit (\S*)$' {
89 # Need return statement to prevent fall-through.
90 return $tortoiseGitCommands | where { $_ -like "$($matches[1])*" }
91 }
92
9ecab15 @dahlbyk Operation completion for remote and stash
authored
93 # Handles git remote <op>
94 # Handles git stash <op>
242138d @JeremySkinner Add support for git svn tab expansion
JeremySkinner authored
95 'git (remote|stash|svn) (\S*)$' {
9ecab15 @dahlbyk Operation completion for remote and stash
authored
96 gitCmdOperations $matches[1] $matches[2]
97 }
8c526cb Stash completion
unknown authored
98
99 # Handles git stash (show|apply|drop|pop|branch) <stash>
100 'git stash (show|apply|drop|pop|branch) (\S*)$' {
101 gitStashes $matches[2]
102 }
9ecab15 @dahlbyk Operation completion for remote and stash
authored
103
d1a35c5 @dahlbyk Tab completion for branch rename
authored
104 # Handles git branch -d|-D|-m|-M <branch name>
105 'git branch -(d|D|m|M) (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
106 gitLocalBranches $matches[2]
3033fa5 @dahlbyk Rough start
authored
107 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
108
109 # Handles git checkout <branch name>
110 # Handles git merge <branch name>
4b46e7b @JeremySkinner Tab expansion for "git rebase <branch name>"
JeremySkinner authored
111 # handles git rebase <branch name>
112 'git (checkout|merge|rebase) (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
113 gitLocalBranches $matches[2]
3033fa5 @dahlbyk Rough start
authored
114 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
115
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
116 # Handles git <cmd> (commands & aliases)
117 'git (\S*)$' {
040dee1 @dahlbyk Remove GitTabExpansion -advanced parameter
authored
118 gitCommands $matches[1] $TRUE
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
119 }
120
121 # Handles git help <cmd> (commands only)
122 'git help (\S*)$' {
040dee1 @dahlbyk Remove GitTabExpansion -advanced parameter
authored
123 gitCommands $matches[1] $FALSE
3033fa5 @dahlbyk Rough start
authored
124 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
125
126 # Handles git push remote <branch>
127 # Handles git pull remote <branch>
3033fa5 @dahlbyk Rough start
authored
128 'git (push|pull) (\S+) (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
129 gitLocalBranches $matches[3]
3033fa5 @dahlbyk Rough start
authored
130 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
131
132 # Handles git pull <remote>
133 # Handles git push <remote>
3033fa5 @dahlbyk Rough start
authored
134 'git (push|pull) (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
135 gitRemotes $matches[2]
3033fa5 @dahlbyk Rough start
authored
136 }
137
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
138 # Handles git reset HEAD <path>
3033fa5 @dahlbyk Rough start
authored
139 'git reset HEAD (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
140 gitIndex $matches[1]
3033fa5 @dahlbyk Rough start
authored
141 }
142
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
143 # Handles git add <path>
3033fa5 @dahlbyk Rough start
authored
144 'git add (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
145 gitFiles $matches[1]
3033fa5 @dahlbyk Rough start
authored
146 }
c7511ea @dahlbyk Path completion for 'git checkout -- <tab>'
authored
147
148 # Handles git checkout -- <path>
149 'git checkout -- (\S*)$' {
150 gitFiles $matches[1]
151 }
8c526cb Stash completion
unknown authored
152 }
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
153 }
Something went wrong with that request. Please try again.