summaryrefslogtreecommitdiff
path: root/makeAutocompleteFiles.go
diff options
context:
space:
mode:
Diffstat (limited to 'makeAutocompleteFiles.go')
-rw-r--r--makeAutocompleteFiles.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/makeAutocompleteFiles.go b/makeAutocompleteFiles.go
new file mode 100644
index 0000000..647abe3
--- /dev/null
+++ b/makeAutocompleteFiles.go
@@ -0,0 +1,41 @@
+package prep
+
+// This is where the actual autocomplete happens
+// lots of the fun magic is in here
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "go.wit.com/lib/config"
+ "go.wit.com/log"
+)
+
+// makes a autocomplete file for your command
+func makeAutocompleteFiles(argname string) {
+ fmt.Println(makeBashCompletionText2(argname))
+
+ homeDir, err := os.UserHomeDir()
+ if err != nil {
+ log.Printf("# %v\n", err)
+ os.Exit(0)
+ }
+ filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname)
+ if config.Exists(filename) {
+ log.Fprintln(os.Stderr, "# file already exists", filename)
+ // os.Exit(0)
+ }
+ basedir, _ := filepath.Split(filename)
+ if !config.IsDir(basedir) {
+ os.MkdirAll(basedir, os.ModePerm)
+ }
+
+ if f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil {
+ f.Write([]byte(makeBashCompletionText2(argname)))
+ f.Close()
+ } else {
+ log.Fprintln(os.Stderr, "# open file error", filename, err)
+ }
+ os.Exit(0)
+}