testing
This commit is contained in:
parent
a9a7012293
commit
2d811f1796
37
bash.go
37
bash.go
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var argBash ArgsBash
|
var argBash ArgsBash
|
||||||
|
@ -57,21 +58,31 @@ func Bash(argname string, autocomplete func([]string)) *BashAuto {
|
||||||
|
|
||||||
// makes a bash autocomplete file for your command
|
// makes a bash autocomplete file for your command
|
||||||
func doBash(argname string) {
|
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(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)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue