summaryrefslogtreecommitdiff
path: root/cmd/install/root.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/install/root.go')
-rw-r--r--cmd/install/root.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/install/root.go b/cmd/install/root.go
new file mode 100644
index 0000000..66e23b3
--- /dev/null
+++ b/cmd/install/root.go
@@ -0,0 +1,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
+}