This commit is contained in:
Jeff Carr 2025-09-11 20:03:25 -05:00
parent a9a7012293
commit 2d811f1796
1 changed files with 24 additions and 13 deletions

37
bash.go
View File

@ -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)
}