-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcompletion.go
More file actions
68 lines (63 loc) · 1.87 KB
/
completion.go
File metadata and controls
68 lines (63 loc) · 1.87 KB
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
package cmd
import (
"fmt"
"os"
)
// GetZshCompletion returns the Zsh completion script as a string
func GetZshCompletion() string {
return `#compdef stew
_stew_installed_binaries() {
local -a binaries
binaries=($(stew list 2>/dev/null | tail -n +2 | awk '{print $1}'))
_describe 'installed binaries' binaries
}
_stew() {
local context state state_descr line
_arguments -C \
'1: :->command' \
'*: :->args'
case $state in
command)
local -a commands
commands=(
'install:Install a binary from GitHub or URL'
'i:Install a binary from GitHub or URL'
'search:Search GitHub repos'
's:Search GitHub repos'
'browse:Browse releases and assets'
'b:Browse releases and assets'
'upgrade:Upgrade an installed binary'
'up:Upgrade an installed binary'
'uninstall:Uninstall a binary'
'un:Uninstall a binary'
'rename:Rename an installed binary'
're:Rename an installed binary'
'list:List installed binaries'
'ls:List installed binaries'
'config:Configure stew'
'help:Show help'
'h:Show help'
)
_describe -t commands 'stew command' commands
;;
args)
case $line[1] in
upgrade|up|uninstall|un|rename|re)
_stew_installed_binaries
;;
esac
;;
esac
}
#_stew "$@"`
}
// RunCompletion prints the completion script to stdout
func RunCompletion(shell string) error {
switch shell {
case "zsh":
fmt.Fprintln(os.Stdout, GetZshCompletion())
default:
return fmt.Errorf("unsupported shell: %s (only zsh is supported currently)", shell)
}
return nil
}