summaryrefslogtreecommitdiff
path: root/install/root.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-06 18:55:54 +0300
committerEyal Posener <[email protected]>2017-05-06 18:55:54 +0300
commit4f47fe9246e715f11272d6323343a12797d4d13f (patch)
tree65eb8cd82bbb5da33c548b5510f91f8017b04330 /install/root.go
parentd33bac720bcaf13a5ee9f6f165293183d2e3e24d (diff)
Add easy way to install the bash completion
Diffstat (limited to 'install/root.go')
-rw-r--r--install/root.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/install/root.go b/install/root.go
new file mode 100644
index 0000000..b128a0d
--- /dev/null
+++ b/install/root.go
@@ -0,0 +1,30 @@
+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
+}
+