summaryrefslogtreecommitdiff
path: root/makeAutocompleteFiles.bash.go
diff options
context:
space:
mode:
Diffstat (limited to 'makeAutocompleteFiles.bash.go')
-rw-r--r--makeAutocompleteFiles.bash.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/makeAutocompleteFiles.bash.go b/makeAutocompleteFiles.bash.go
index 43d2bf4..d27f167 100644
--- a/makeAutocompleteFiles.bash.go
+++ b/makeAutocompleteFiles.bash.go
@@ -1,14 +1,44 @@
package prep
-// initializes logging and command line options
+// makes the needed bash completion in the bash standard paths
import (
"fmt"
"io/ioutil"
"os"
+ "path/filepath"
"strings"
+
+ "go.wit.com/lib/config"
+ "go.wit.com/log"
)
+func makeBashCompleteFiles(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)
+ }
+}
+
// deprecate this
func Bash3(dest any) *Auto {
return Autocomplete(dest)