-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP4TabExpansion.ps1
116 lines (113 loc) · 4.15 KB
/
P4TabExpansion.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
<#
.SYNOPSIS
perforce tab completion for windows powershell
.DESCRIPTION
posh-p4 Module:
Bring tab auto completion (/tab expansion) for windows powershell. type p4, press tab, auto complete is there
.NOTES
Author: Frederic ROUSSEAU
#>
#list of p4 commands
$script:p4Cmd = @(
'add'
'annotate'
'attribute'
'branch'
'branches'
'change'
'changes'
'changelist'
'changelists'
'clean'
'client'
'clients'
'copy'
'counter'
'counters'
'cstat'
'delete'
'depot'
'depots'
'describe'
'diff'
'diff2'
'dirs'
'edit'
'filelog'
'files'
'fix'
'fixes'
'flush'
'fstat'
'grep'
'group'
'groups'
'have'
'help'
'info'
'integrate'
'integrated'
'interchanges'
'istat'
'job'
'jobs'
'key'
'keys'
'label'
'labels'
'labelsync'
'list'
'lock'
'logger'
'login'
'logout'
'merge'
'move'
'opened'
'passwd'
'populate'
'print'
'protect'
'protects'
'prune'
'rec'
'reconcile'
'rename'
'reopen'
'resolve'
'resolved'
'revert'
'review'
'reviews'
'set'
'shelve'
'status'
'sizes'
'stream'
'streams'
'submit'
'sync'
'tag'
'tickets'
'unlock'
'unshelve'
'update'
'user'
'users'
'where'
'workspace'
'workspaces'
)
#powershell function to act on tab key
function TabExpansion($line, $lastWord) {
$lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart()
$words = $lastBlock.Split(' ')
#we only care about commands that start with "p4 "
if ($words[0] -eq "p4") {
# give tab completion for p4 <tab> and p4 help <tab>
if ($words.length -eq 2 -or (($words.length -eq 3) -and ($words[1] -eq "help")) ) {
#match also p4 <letter><tab>
return $script:p4Cmd | ? { $_ -like "$lastWord*" }
}
}
}