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
|
# The JustEnoughVCS CommandLine Completion
Register-ArgumentCompleter -Native -CommandName jvv -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$words = $commandAst.CommandElements | ForEach-Object { $_.ToString() }
$currentIndex = $words.IndexOf($wordToComplete)
if ($currentIndex -lt 0) { $currentIndex = $words.Count }
$cmd = "jvv"
$subcmd = if ($words.Count -gt 1) { $words[1] } else { $null }
$subsubcmd = if ($words.Count -gt 2) { $words[2] } else { $null }
# Base commands
$baseCommands = @("create", "init", "here", "member", "service", "listen", "members", "-c", "-i", "-H", "-m", "-l", "-M")
# Member subcommands
$memberCommands = @("register", "remove", "list", "help", "+", "-", "ls")
# Service subcommands
$serviceCommands = @("listen", "help")
# Completion for main command
if ($currentIndex -eq 1) {
return $baseCommands | Where-Object { $_ -like "$wordToComplete*" }
}
# Completion for member command
if ($subcmd -eq "member" -or $subcmd -eq "-m") {
if ($currentIndex -eq 2) {
return $memberCommands | Where-Object { $_ -like "$wordToComplete*" }
}
switch ($subsubcmd) {
{ @("remove", "-") -contains $_ } {
if ($currentIndex -eq 3) {
$members = & $cmd member list --raw 2>$null
return $members | Where-Object { $_ -like "$wordToComplete*" }
}
}
}
return @()
}
# Completion for service command
if ($subcmd -eq "service") {
if ($currentIndex -eq 2) {
return $serviceCommands | Where-Object { $_ -like "$wordToComplete*" }
}
return @()
}
# Aliases completion
switch ($subcmd) {
"-m" {
if ($currentIndex -eq 2) {
return $memberCommands | Where-Object { $_ -like "$wordToComplete*" }
}
}
{ @("listen", "-l", "members", "-M") -contains $_ } {
# These commands have no arguments to complete
return @()
}
}
return @()
}
|