summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-12 03:49:38 -0500
committerJeff Carr <[email protected]>2025-10-12 03:49:38 -0500
commit12195649cd8610533082d2cfb10568fe4c080a4d (patch)
tree10444fdad426e27e001d3cbb14f55fe30b7dc45c
parent3db85febbf02380bc5c38abd660668f1ef53a9c8 (diff)
stub in zsh
-rw-r--r--makeAutocompleteFiles.bash.go32
-rw-r--r--makeAutocompleteFiles.go50
-rw-r--r--makeAutocompleteFiles.zsh.go6
3 files changed, 41 insertions, 47 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)
diff --git a/makeAutocompleteFiles.go b/makeAutocompleteFiles.go
index 57bf391..2d19114 100644
--- a/makeAutocompleteFiles.go
+++ b/makeAutocompleteFiles.go
@@ -1,57 +1,15 @@
package prep
-// This is where the actual autocomplete happens
-// lots of the fun magic is in here
-
import (
- "fmt"
"os"
- "path/filepath"
-
- "go.wit.com/lib/config"
- "go.wit.com/log"
)
-func detectShell() string {
- // Zsh sets ZSH_VERSION. We use os.LookupEnv which returns a boolean
- // indicating if the variable is present.
- if _, ok := os.LookupEnv("ZSH_VERSION"); ok {
- return "zsh"
- }
-
- // Bash sets BASH_VERSION.
- if _, ok := os.LookupEnv("BASH_VERSION"); ok {
- return "bash"
- }
-
- // Fallback if neither is found.
- return "unknown"
-}
-
-// makes a autocomplete file for your command
func makeAutocompleteFiles(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 _, ok := os.LookupEnv("BASH_VERSION"); ok {
+ makeBashCompleteFiles(argname)
}
- 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)
+ if _, ok := os.LookupEnv("ZSH_VERSION"); ok {
+ makeZshCompleteFiles(argname)
}
- os.Exit(0)
}
diff --git a/makeAutocompleteFiles.zsh.go b/makeAutocompleteFiles.zsh.go
index b48ca48..ca8f4be 100644
--- a/makeAutocompleteFiles.zsh.go
+++ b/makeAutocompleteFiles.zsh.go
@@ -1,7 +1,13 @@
package prep
+import "go.wit.com/log"
+
// makes the autocomplete files for 'zsh'
+func makeZshCompleteFiles(argname string) {
+ log.Info("todo: zsh")
+}
+
/*
This script will be placed in a directory in your $fpath (e.g., ~/.zsh/completions/_my-app).