From 763b1a60fcc9c6c0e6751859a6c06c81372d0268 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 18 Sep 2025 08:54:33 -0500 Subject: [PATCH] still working on how this should work --- bash.new.go | 5 +++-- bash.orig.go | 32 +++++++++++++------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/bash.new.go b/bash.new.go index 631e5b4..fcee961 100644 --- a/bash.new.go +++ b/bash.new.go @@ -28,7 +28,7 @@ func doBash2(argname string) { filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname) if shell.Exists(filename) { log.Println(filename, "file already exists") - os.Exit(0) + // os.Exit(0) } basedir, _ := filepath.Split(filename) if !shell.IsDir(basedir) { @@ -215,7 +215,7 @@ func parseArgv(argname string) *Auto { } // also try to parse/send cur (?) -func Bash2(argname string, autocomplete func(*Auto)) { +func Bash2(argname string, autocomplete func(*Auto)) *Auto { newauto := parseArgv(argname) if newauto.SetupAuto { // --bash was passed. try to configure bash-completion @@ -239,4 +239,5 @@ func Bash2(argname string, autocomplete func(*Auto)) { } arg.Register(&argBash) + return newauto } diff --git a/bash.orig.go b/bash.orig.go index e0d23bd..2d32a05 100644 --- a/bash.orig.go +++ b/bash.orig.go @@ -13,35 +13,32 @@ import ( "go.wit.com/log" ) -var argBash ArgsBash - /* This struct can be used with the go-arg package. These are the generic default command line arguments for the 'GUI' package */ +var argBash ArgsBash + type ArgsBash struct { Bash bool `arg:"--bash" help:"generate bash completion"` } -var myBash *BashAuto +// try this struct out (?) +var myAuto *AutoArgs -type BashAuto struct { +type AutoArgs struct { id int // should be unique hidden bool // don't update the toolkits when it's hidden Auto func([]string) - appName string // a good way to track the name of the binary ? + appName string // a good way to track the name of the binary ? + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! } -/* -func dumpjunk() { - fmt.Fprintln(os.Stderr, "") - fmt.Fprintln(os.Stderr, os.Args) - os.Exit(0) -} -*/ - // argname is the name of the executable -func Bash(argname string, autocomplete func([]string)) *BashAuto { +func Bash(argname string, autocomplete func([]string)) *AutoArgs { + myAuto = new(AutoArgs) + myAuto.appName = argname + if len(os.Args) > 1 && os.Args[1] == "--bash" { doBash(argname) os.Exit(0) @@ -54,11 +51,8 @@ func Bash(argname string, autocomplete func([]string)) *BashAuto { arg.Register(&argBash) - myBash = new(BashAuto) - myBash.appName = argname - // parse go.Arg here? - return myBash + return myAuto } // print out auto complete debugging info @@ -84,7 +78,7 @@ func GetLast(cur string, argv []string) string { // returns the name of the executable registered for shell autocomplete func AppName() string { - return myBash.appName + return myAuto.appName } // makes a bash autocomplete file for your command