-
Notifications
You must be signed in to change notification settings - Fork 223
/
bash.go
46 lines (38 loc) · 1.17 KB
/
bash.go
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
package bash
//go:generate go run ../generate_scripts.go
import (
"fmt"
"github.com/jfrog/jfrog-cli-core/utils/coreutils"
"github.com/jfrog/jfrog-client-go/utils/log"
"io/ioutil"
"path/filepath"
)
const BashAutocomplete = `#!/bin/bash
_jfrog() {
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
}
complete -F _jfrog -o default jfrog
`
func WriteBashCompletionScript() {
homeDir, err := coreutils.GetJfrogHomeDir()
if err != nil {
log.Error(err)
return
}
completionPath := filepath.Join(homeDir, "jfrog_bash_completion")
if err = ioutil.WriteFile(completionPath, []byte(BashAutocomplete), 0600); err != nil {
log.Error(err)
return
}
sourceCommand := "source " + completionPath + ""
fmt.Printf(`Generated bash completion script at %s.
To activate auto-completion on this shell only, source the completion script by running the following command:
%s
To activate auto-completion permanently, put the above command in ~/.bashrc or ~/.bash_profile, depending on your operating system.
`,
completionPath, sourceCommand)
}