commit
0d98d7ee19
|
@ -16,7 +16,10 @@ type fish struct {
|
||||||
|
|
||||||
func (f fish) Install(cmd, bin string) error {
|
func (f fish) Install(cmd, bin string) error {
|
||||||
completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
|
completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
|
||||||
completeCmd := f.cmd(cmd, bin)
|
completeCmd, err := f.cmd(cmd, bin)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if _, err := os.Stat(completionFile); err == nil {
|
if _, err := os.Stat(completionFile); err == nil {
|
||||||
return fmt.Errorf("already installed at %s", completionFile)
|
return fmt.Errorf("already installed at %s", completionFile)
|
||||||
}
|
}
|
||||||
|
@ -33,10 +36,10 @@ func (f fish) Uninstall(cmd, bin string) error {
|
||||||
return os.Remove(completionFile)
|
return os.Remove(completionFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f fish) cmd(cmd, bin string) string {
|
func (f fish) cmd(cmd, bin string) (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
params := struct{ Cmd, Bin string }{cmd, bin}
|
params := struct{ Cmd, Bin string }{cmd, bin}
|
||||||
template.Must(template.New("cmd").Parse(`
|
tmpl := template.Must(template.New("cmd").Parse(`
|
||||||
function __complete_{{.Cmd}}
|
function __complete_{{.Cmd}}
|
||||||
set -lx COMP_LINE (string join ' ' (commandline -o))
|
set -lx COMP_LINE (string join ' ' (commandline -o))
|
||||||
test (commandline -ct) = ""
|
test (commandline -ct) = ""
|
||||||
|
@ -44,7 +47,10 @@ function __complete_{{.Cmd}}
|
||||||
{{.Bin}}
|
{{.Bin}}
|
||||||
end
|
end
|
||||||
complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
|
complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
|
||||||
`)).Execute(&buf, params)
|
`))
|
||||||
|
err := tmpl.Execute(&buf, params)
|
||||||
return buf.String()
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return buf.String(), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ func Uninstall(cmd string) error {
|
||||||
for _, i := range is {
|
for _, i := range is {
|
||||||
errI := i.Uninstall(cmd, bin)
|
errI := i.Uninstall(cmd, bin)
|
||||||
if errI != nil {
|
if errI != nil {
|
||||||
multierror.Append(err, errI)
|
err = multierror.Append(err, errI)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,10 @@ func removeContentToTempFile(name, content string) (string, error) {
|
||||||
if str == content {
|
if str == content {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
wf.WriteString(str + "\n")
|
_, err = wf.WriteString(str + "\n")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
prefix = prefix[:0]
|
prefix = prefix[:0]
|
||||||
}
|
}
|
||||||
return wf.Name(), nil
|
return wf.Name(), nil
|
||||||
|
|
Loading…
Reference in New Issue