aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/posener/complete/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/posener/complete/cmd')
-rw-r--r--vendor/github.com/posener/complete/cmd/cmd.go2
-rw-r--r--vendor/github.com/posener/complete/cmd/install/fish.go56
-rw-r--r--vendor/github.com/posener/complete/cmd/install/install.go29
-rw-r--r--vendor/github.com/posener/complete/cmd/install/utils.go24
4 files changed, 108 insertions, 3 deletions
diff --git a/vendor/github.com/posener/complete/cmd/cmd.go b/vendor/github.com/posener/complete/cmd/cmd.go
index 7137dee..b99fe52 100644
--- a/vendor/github.com/posener/complete/cmd/cmd.go
+++ b/vendor/github.com/posener/complete/cmd/cmd.go
@@ -103,7 +103,7 @@ func (f *CLI) AddFlags(flags *flag.FlagSet) {
103 fmt.Sprintf("Uninstall completion for %s command", f.Name)) 103 fmt.Sprintf("Uninstall completion for %s command", f.Name))
104 } 104 }
105 if flags.Lookup("y") == nil { 105 if flags.Lookup("y") == nil {
106 flags.BoolVar(&f.yes, "y", false, "Don't prompt user for typing 'yes'") 106 flags.BoolVar(&f.yes, "y", false, "Don't prompt user for typing 'yes' when installing completion")
107 } 107 }
108} 108}
109 109
diff --git a/vendor/github.com/posener/complete/cmd/install/fish.go b/vendor/github.com/posener/complete/cmd/install/fish.go
new file mode 100644
index 0000000..6467196
--- /dev/null
+++ b/vendor/github.com/posener/complete/cmd/install/fish.go
@@ -0,0 +1,56 @@
1package install
2
3import (
4 "bytes"
5 "fmt"
6 "os"
7 "path/filepath"
8 "text/template"
9)
10
11// (un)install in fish
12
13type fish struct {
14 configDir string
15}
16
17func (f fish) Install(cmd, bin string) error {
18 completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
19 completeCmd, err := f.cmd(cmd, bin)
20 if err != nil {
21 return err
22 }
23 if _, err := os.Stat(completionFile); err == nil {
24 return fmt.Errorf("already installed at %s", completionFile)
25 }
26
27 return createFile(completionFile, completeCmd)
28}
29
30func (f fish) Uninstall(cmd, bin string) error {
31 completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
32 if _, err := os.Stat(completionFile); err != nil {
33 return fmt.Errorf("does not installed in %s", f.configDir)
34 }
35
36 return os.Remove(completionFile)
37}
38
39func (f fish) cmd(cmd, bin string) (string, error) {
40 var buf bytes.Buffer
41 params := struct{ Cmd, Bin string }{cmd, bin}
42 tmpl := template.Must(template.New("cmd").Parse(`
43function __complete_{{.Cmd}}
44 set -lx COMP_LINE (string join ' ' (commandline -o))
45 test (commandline -ct) = ""
46 and set COMP_LINE "$COMP_LINE "
47 {{.Bin}}
48end
49complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
50`))
51 err := tmpl.Execute(&buf, params)
52 if err != nil {
53 return "", err
54 }
55 return buf.String(), nil
56}
diff --git a/vendor/github.com/posener/complete/cmd/install/install.go b/vendor/github.com/posener/complete/cmd/install/install.go
index 082a226..dfa1963 100644
--- a/vendor/github.com/posener/complete/cmd/install/install.go
+++ b/vendor/github.com/posener/complete/cmd/install/install.go
@@ -51,7 +51,7 @@ func Uninstall(cmd string) error {
51 for _, i := range is { 51 for _, i := range is {
52 errI := i.Uninstall(cmd, bin) 52 errI := i.Uninstall(cmd, bin)
53 if errI != nil { 53 if errI != nil {
54 multierror.Append(err, errI) 54 err = multierror.Append(err, errI)
55 } 55 }
56 } 56 }
57 57
@@ -68,9 +68,36 @@ func installers() (i []installer) {
68 if f := rcFile(".zshrc"); f != "" { 68 if f := rcFile(".zshrc"); f != "" {
69 i = append(i, zsh{f}) 69 i = append(i, zsh{f})
70 } 70 }
71 if d := fishConfigDir(); d != "" {
72 i = append(i, fish{d})
73 }
71 return 74 return
72} 75}
73 76
77func fishConfigDir() string {
78 configDir := filepath.Join(getConfigHomePath(), "fish")
79 if configDir == "" {
80 return ""
81 }
82 if info, err := os.Stat(configDir); err != nil || !info.IsDir() {
83 return ""
84 }
85 return configDir
86}
87
88func getConfigHomePath() string {
89 u, err := user.Current()
90 if err != nil {
91 return ""
92 }
93
94 configHome := os.Getenv("XDG_CONFIG_HOME")
95 if configHome == "" {
96 return filepath.Join(u.HomeDir, ".config")
97 }
98 return configHome
99}
100
74func getBinaryPath() (string, error) { 101func getBinaryPath() (string, error) {
75 bin, err := os.Executable() 102 bin, err := os.Executable()
76 if err != nil { 103 if err != nil {
diff --git a/vendor/github.com/posener/complete/cmd/install/utils.go b/vendor/github.com/posener/complete/cmd/install/utils.go
index 2c8b44c..d34ac8c 100644
--- a/vendor/github.com/posener/complete/cmd/install/utils.go
+++ b/vendor/github.com/posener/complete/cmd/install/utils.go
@@ -6,6 +6,7 @@ import (
6 "io" 6 "io"
7 "io/ioutil" 7 "io/ioutil"
8 "os" 8 "os"
9 "path/filepath"
9) 10)
10 11
11func lineInFile(name string, lookFor string) bool { 12func lineInFile(name string, lookFor string) bool {
@@ -36,6 +37,24 @@ func lineInFile(name string, lookFor string) bool {
36 } 37 }
37} 38}
38 39
40func createFile(name string, content string) error {
41 // make sure file directory exists
42 if err := os.MkdirAll(filepath.Dir(name), 0775); err != nil {
43 return err
44 }
45
46 // create the file
47 f, err := os.Create(name)
48 if err != nil {
49 return err
50 }
51 defer f.Close()
52
53 // write file content
54 _, err = f.WriteString(fmt.Sprintf("%s\n", content))
55 return err
56}
57
39func appendToFile(name string, content string) error { 58func appendToFile(name string, content string) error {
40 f, err := os.OpenFile(name, os.O_RDWR|os.O_APPEND, 0) 59 f, err := os.OpenFile(name, os.O_RDWR|os.O_APPEND, 0)
41 if err != nil { 60 if err != nil {
@@ -96,7 +115,10 @@ func removeContentToTempFile(name, content string) (string, error) {
96 if str == content { 115 if str == content {
97 continue 116 continue
98 } 117 }
99 wf.WriteString(str + "\n") 118 _, err = wf.WriteString(str + "\n")
119 if err != nil {
120 return "", err
121 }
100 prefix = prefix[:0] 122 prefix = prefix[:0]
101 } 123 }
102 return wf.Name(), nil 124 return wf.Name(), nil