github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/completion/shells/bash/bash.go (about) 1 package bash 2 3 //go:generate go run ../generate_scripts.go 4 5 import ( 6 "fmt" 7 "github.com/jfrog/jfrog-cli-go/utils/cliutils" 8 "github.com/jfrog/jfrog-client-go/utils/log" 9 "io/ioutil" 10 "path/filepath" 11 ) 12 13 const BashAutocomplete = `#!/bin/bash 14 _jfrog() { 15 local cur opts base 16 COMPREPLY=() 17 cur="${COMP_WORDS[COMP_CWORD]}" 18 opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) 19 COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) 20 } 21 22 complete -F _jfrog -o default jfrog 23 ` 24 25 func WriteBashCompletionScript() { 26 homeDir, err := cliutils.GetJfrogHomeDir() 27 if err != nil { 28 log.Error(err) 29 return 30 } 31 completionPath := filepath.Join(homeDir, "jfrog_bash_completion") 32 if err = ioutil.WriteFile(completionPath, []byte(BashAutocomplete), 0600); err != nil { 33 log.Error(err) 34 return 35 } 36 sourceCommand := "source " + completionPath + "" 37 fmt.Printf(`Generated bash completion script at %s. 38 To activate auto-completion on this shell only, source the completion script by running the following command: 39 40 %s 41 42 To activate auto-completion permanently, put the above command in ~/.bashrc or ~/.bash_profile, depending on your operating system. 43 44 `, 45 completionPath, sourceCommand) 46 }