diff options
| author | Jeff Carr <[email protected]> | 2025-10-12 00:11:00 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-12 00:11:00 -0500 |
| commit | 2d5370c9a6dd8ab566ec2943e20738b31a7a6606 (patch) | |
| tree | c714dafa13c6763ded14638cee98cf33b79786c7 | |
| parent | 7144347aa7dc1e53bb5df051a2c5c3eaacbb34c6 (diff) | |
restructure code
| -rw-r--r-- | auto.Complete.go (renamed from complete.go) | 0 | ||||
| -rw-r--r-- | bash.go (renamed from shell.go) | 0 | ||||
| -rw-r--r-- | exit.go | 34 | ||||
| -rw-r--r-- | smartcd.test | 20 | ||||
| -rw-r--r-- | structs.go (renamed from bash.orig.go) | 55 |
5 files changed, 33 insertions, 76 deletions
diff --git a/complete.go b/auto.Complete.go index 4de01db..4de01db 100644 --- a/complete.go +++ b/auto.Complete.go @@ -1,6 +1,7 @@ package prep import ( + "fmt" "os" "time" @@ -8,15 +9,21 @@ import ( "go.wit.com/log" ) -// initializes logging and command line options +// since we know when the command starts (duh, this parses os.Args) +// this is a convienent way to provide a standard exit format back +// to the shell that also has built in timing! + +// also, it supports a custom Exit() back to your application func (pb *Auto) GoodExit(msg string) { + go ExitWatchdog() dur := time.Since(pb.Ctime.AsTime()) log.Infof("%s: %s (%s)\n", pb.Argname, msg, config.FormatDuration(dur)) os.Exit(0) } func (pb *Auto) BadExit(msg string, err error) { + go ExitWatchdog() if err != nil { log.Info(err) } @@ -24,3 +31,28 @@ func (pb *Auto) BadExit(msg string, err error) { log.Infof("%s: %s (%s)\n", pb.Argname, msg, config.FormatDuration(dur)) os.Exit(-1) } + +// this code doesn't need to be this complicated. I put it here as reference code for myself so I could remember where it is. +func ExitWatchdog() { + dog := time.NewTicker(time.Second) + defer dog.Stop() + dogchan := make(chan bool) + /* + // this example would exit/destroy the ticker in 10 seconds + go func() { + time.Sleep(10 * time.Second) + done <- true + }() + */ + for { + select { + case <-dogchan: + fmt.Println("Done!") + return + case t := <-dog.C: + _ = t + log.Info("argv.Exit() watchdog: stalled in", myAuto.appName+".Exit()") + // h.Scan() + } + } +} diff --git a/smartcd.test b/smartcd.test deleted file mode 100644 index d476814..0000000 --- a/smartcd.test +++ /dev/null @@ -1,20 +0,0 @@ -# could work like 'z' ? - -_cd_complete() -{ - # sets local to this func vars - local cur prev all - cur=${COMP_WORDS[COMP_CWORD]} - # prev=${COMP_WORDS[COMP_CWORD-1]} - all=${COMP_WORDS[@]} - - # this is where we generate the go-arg output - GOARGS=$(smartcd --auto-complete \'$cur\' $all) - - # this compares the command line input from the user - # to whatever strings we output - COMPREPLY=( $(compgen -W "$GOARGS" -- $cur) ) # THIS WORKS - return 0 -} -complete -F _cd_complete cd - diff --git a/bash.orig.go b/structs.go index 7d431cc..1f274f1 100644 --- a/bash.orig.go +++ b/structs.go @@ -81,58 +81,3 @@ func GetLast(cur string, argv []string) string { func AppName() string { return myAuto.appName } - -/* -// makes a bash autocomplete file for your command -func doBash(argname string) { - fmt.Println(makeBashCompletionText(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.Println(filename, "file already exists") - 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(makeBashCompletionText(argname))) - f.Close() - log.Println("bash file created:", filename) - log.Println("restart bash") - } else { - log.Info(filename, err) - } - os.Exit(0) -} -*/ - -/* -// argname is the name of the executable -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) - } - - if len(os.Args) > 1 && os.Args[1] == "--auto-complete" { - autocomplete(os.Args[2:]) - os.Exit(0) - } - - arg.Register(&argBash) - - // parse go.Arg here? - return myAuto -} -*/ |
