diff options
| author | Jeff Carr <[email protected]> | 2025-09-11 20:03:25 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-11 20:03:25 -0500 |
| commit | 2d811f1796f8075c1e3618d54bfd3118d3590899 (patch) | |
| tree | a1d4ea513b3f10f8cc01158e4515cef6af4f685d | |
| parent | a9a7012293029de8e17f521259fa2b85fa70b82d (diff) | |
testing
| -rw-r--r-- | bash.go | 37 |
1 files changed, 24 insertions, 13 deletions
@@ -9,6 +9,7 @@ import ( "go.wit.com/dev/alexflint/arg" "go.wit.com/lib/gui/shell" + "go.wit.com/log" ) var argBash ArgsBash @@ -57,21 +58,31 @@ func Bash(argname string, autocomplete func([]string)) *BashAuto { // makes a bash autocomplete file for your command func doBash(argname string) { - if homeDir, err := os.UserHomeDir(); err == nil { - filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname) - if shell.Exists(filename) { - } else { - if f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644); err == nil { - f.Write([]byte(makeBashCompletionText(argname))) - f.Close() - } - fmt.Println("bash file created:", filename) - } - } - fmt.Println(makeBashCompletionText(argname)) - fmt.Println("restart bash") + 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 shell.Exists(filename) { + log.Println(filename, "file already exists") + os.Exit(0) + } + basedir, _ := filepath.Split(filename) + if !shell.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(makeBashCompletionText(argname))) + f.Close() + log.Println("bash file created:", filename) + log.Println("restart bash") + } else { + log.Info(filename, err) + } os.Exit(0) } |
