summaryrefslogtreecommitdiff
path: root/makeAutocompleteFiles.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-12 02:11:40 -0500
committerJeff Carr <[email protected]>2025-10-12 02:11:40 -0500
commit0c84559372b1d4c293ac10aa2b6de6e53ebb1163 (patch)
tree14c92db2cbe6544c0c6b742e006d4736fe8da1d7 /makeAutocompleteFiles.go
parentbf9f85a721d6045e631df9abe91f02d9723fcd19 (diff)
more housecleaning
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)
+}