summaryrefslogtreecommitdiff
path: root/install/root.go
blob: 66e23b34e785d6b60b40bb9571b13decd55d2607 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package install

import "os"

type root struct{}

func (r root) Install(cmd string, bin string) error {
	completeLink := getBashCompletionDLink(cmd)
	err := r.Uninstall(cmd, bin)
	if err != nil {
		return err
	}
	return os.Symlink(bin, completeLink)
}

func (root) Uninstall(cmd string, bin string) error {
	completeLink := getBashCompletionDLink(cmd)
	if _, err := os.Stat(completeLink); err == nil {
		err := os.Remove(completeLink)
		if err != nil {
			return err
		}
	}
	return nil
}

func getBashCompletionDLink(cmd string) string {
	return "/etc/bash_completion.d/" + cmd
}