9 "github.com/hashicorp/go-multierror"
12 type installer interface {
13 Install(cmd, bin string) error
14 Uninstall(cmd, bin string) error
17 // Install complete command given:
18 // cmd: is the command name
19 func Install(cmd string) error {
22 return errors.New("Did not find any shells to install")
24 bin, err := getBinaryPath()
29 for _, i := range is {
30 errI := i.Install(cmd, bin)
32 err = multierror.Append(err, errI)
39 // Uninstall complete command given:
40 // cmd: is the command name
41 func Uninstall(cmd string) error {
44 return errors.New("Did not find any shells to uninstall")
46 bin, err := getBinaryPath()
51 for _, i := range is {
52 errI := i.Uninstall(cmd, bin)
54 err = multierror.Append(err, errI)
61 func installers() (i []installer) {
62 for _, rc := range [...]string{".bashrc", ".bash_profile", ".bash_login", ".profile"} {
63 if f := rcFile(rc); f != "" {
64 i = append(i, bash{f})
68 if f := rcFile(".zshrc"); f != "" {
71 if d := fishConfigDir(); d != "" {
72 i = append(i, fish{d})
77 func fishConfigDir() string {
78 configDir := filepath.Join(getConfigHomePath(), "fish")
82 if info, err := os.Stat(configDir); err != nil || !info.IsDir() {
88 func getConfigHomePath() string {
89 u, err := user.Current()
94 configHome := os.Getenv("XDG_CONFIG_HOME")
96 return filepath.Join(u.HomeDir, ".config")
101 func getBinaryPath() (string, error) {
102 bin, err := os.Executable()
106 return filepath.Abs(bin)
109 func rcFile(name string) string {
110 u, err := user.Current()
114 path := filepath.Join(u.HomeDir, name)
115 if _, err := os.Stat(path); err != nil {