summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-11 20:03:25 -0500
committerJeff Carr <[email protected]>2025-09-11 20:03:25 -0500
commit2d811f1796f8075c1e3618d54bfd3118d3590899 (patch)
treea1d4ea513b3f10f8cc01158e4515cef6af4f685d
parenta9a7012293029de8e17f521259fa2b85fa70b82d (diff)
testing
-rw-r--r--bash.go37
1 files changed, 24 insertions, 13 deletions
diff --git a/bash.go b/bash.go
index 118a635..51f39a7 100644
--- a/bash.go
+++ b/bash.go
@@ -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)
}