2022-04-03 04:07:16 +00:00
|
|
|
package install
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
// (un)install in bash
|
|
|
|
// basically adds/remove from .bashrc:
|
|
|
|
//
|
|
|
|
// complete -C </path/to/completion/command> <command>
|
|
|
|
type bash struct {
|
|
|
|
rc string
|
|
|
|
}
|
|
|
|
|
2022-12-18 17:14:23 +00:00
|
|
|
func (b bash) IsInstalled(cmd, bin string) bool {
|
2022-04-03 04:07:16 +00:00
|
|
|
completeCmd := b.cmd(cmd, bin)
|
2022-12-18 17:14:23 +00:00
|
|
|
return lineInFile(b.rc, completeCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b bash) Install(cmd, bin string) error {
|
|
|
|
if b.IsInstalled(cmd, bin) {
|
2022-04-03 04:07:16 +00:00
|
|
|
return fmt.Errorf("already installed in %s", b.rc)
|
|
|
|
}
|
2022-12-18 17:14:23 +00:00
|
|
|
completeCmd := b.cmd(cmd, bin)
|
2022-04-03 04:07:16 +00:00
|
|
|
return appendToFile(b.rc, completeCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b bash) Uninstall(cmd, bin string) error {
|
2022-12-18 17:14:23 +00:00
|
|
|
if !b.IsInstalled(cmd, bin) {
|
2022-04-03 04:07:16 +00:00
|
|
|
return fmt.Errorf("does not installed in %s", b.rc)
|
|
|
|
}
|
|
|
|
|
2022-12-18 17:14:23 +00:00
|
|
|
completeCmd := b.cmd(cmd, bin)
|
2022-04-03 04:07:16 +00:00
|
|
|
return removeFromFile(b.rc, completeCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bash) cmd(cmd, bin string) string {
|
|
|
|
return fmt.Sprintf("complete -C %s %s", bin, cmd)
|
|
|
|
}
|