Skip to content
Newer
Older
100644 113 lines (95 sloc) 3.15 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
8 function script:gitCommands($filter, $includeAliases) {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
9 $cmdList = @()
6daf5c8 @dahlbyk Add GitTabSettings
authored
10 if (-not $global:GitTabSettings.AllCommands) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
11 $cmdList += git help |
12 foreach { if($_ -match '^ (\S+) (.*)') { $matches[1] } } |
13 where { $_ -like "$filter*" }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
14 } else {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
15 $cmdList += git help --all |
16 where { $_ -match '^ \S.*' } |
17 foreach { $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) } |
18 where { $_ -like "$filter*" }
3033fa5 @dahlbyk Rough start
authored
19 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
20
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
21 if ($includeAliases) {
22 $cmdList += gitAliases $filter
23 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
24 $cmdList | sort
3033fa5 @dahlbyk Rough start
authored
25 }
26
27 function script:gitRemotes($filter) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
28 git remote |
29 where { $_ -like "$filter*" }
3033fa5 @dahlbyk Rough start
authored
30 }
31
32 function script:gitLocalBranches($filter) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
33 git branch |
34 foreach { if($_ -match "^\*?\s*(.*)") { $matches[1] } } |
35 where { $_ -like "$filter*" }
3033fa5 @dahlbyk Rough start
authored
36 }
37
38 function script:gitIndex($filter) {
39 if($GitStatus) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
40 $GitStatus.Index |
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
41 where { $_ -like "$filter*" } |
42 foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
3033fa5 @dahlbyk Rough start
authored
43 }
44 }
45
46 function script:gitFiles($filter) {
47 if($GitStatus) {
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
48 $GitStatus.Working |
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
49 where { $_ -like "$filter*" } |
50 foreach { if($_ -like '* *') { "'$_'" } else { $_ } }
3033fa5 @dahlbyk Rough start
authored
51 }
52 }
53
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
54 function script:gitAliases($filter) {
55 $aliasList = @()
56 git config --get-regexp alias\..+ | foreach {
57 $alias = $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries)[0].Split(
58 '.', [StringSplitOptions]::RemoveEmptyEntries)[1]
59
4864330 Simplify tab filtering a bit and make case-insensitive
unknown authored
60 if($alias -like "$filter*") {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
61 $aliasList += $alias.Trim()
62 }
63 }
64 $aliasList | Sort
65 }
66
133fba1 @dahlbyk Revert "Adjust function scoping"
authored
67 function GitTabExpansion($lastBlock) {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
68 switch -regex ($lastBlock) {
69 # Handles git branch -d|-D <branch name>
3033fa5 @dahlbyk Rough start
authored
70 'git branch -(d|D) (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
71 gitLocalBranches $matches[2]
3033fa5 @dahlbyk Rough start
authored
72 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
73
74 # Handles git checkout <branch name>
75 # Handles git merge <branch name>
3033fa5 @dahlbyk Rough start
authored
76 'git (checkout|merge) (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
77 gitLocalBranches $matches[2]
3033fa5 @dahlbyk Rough start
authored
78 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
79
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
80 # Handles git <cmd> (commands & aliases)
81 'git (\S*)$' {
040dee1 @dahlbyk Remove GitTabExpansion -advanced parameter
authored
82 gitCommands $matches[1] $TRUE
06798ba @markembling Don't include aliases when completing 'git help ...'
markembling authored
83 }
84
85 # Handles git help <cmd> (commands only)
86 'git help (\S*)$' {
040dee1 @dahlbyk Remove GitTabExpansion -advanced parameter
authored
87 gitCommands $matches[1] $FALSE
3033fa5 @dahlbyk Rough start
authored
88 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
89
90 # Handles git push remote <branch>
91 # Handles git pull remote <branch>
3033fa5 @dahlbyk Rough start
authored
92 'git (push|pull) (\S+) (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
93 gitLocalBranches $matches[3]
3033fa5 @dahlbyk Rough start
authored
94 }
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
95
96 # Handles git pull <remote>
97 # Handles git push <remote>
3033fa5 @dahlbyk Rough start
authored
98 'git (push|pull) (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
99 gitRemotes $matches[2]
3033fa5 @dahlbyk Rough start
authored
100 }
101
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
102 # Handles git reset HEAD <path>
3033fa5 @dahlbyk Rough start
authored
103 'git reset HEAD (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
104 gitIndex $matches[1]
3033fa5 @dahlbyk Rough start
authored
105 }
106
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
107 # Handles git add <path>
3033fa5 @dahlbyk Rough start
authored
108 'git add (\S*)$' {
eeb1aa0 @markembling Added ability to show advanced git commands if required.
markembling authored
109 gitFiles $matches[1]
3033fa5 @dahlbyk Rough start
authored
110 }
111 }
2c3f480 @dahlbyk Fix tab completion for file names with spaces
authored
112 }
Something went wrong with that request. Please try again.