still working on how this should work
This commit is contained in:
parent
fec80aca17
commit
763b1a60fc
|
@ -28,7 +28,7 @@ func doBash2(argname string) {
|
||||||
filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname)
|
filename := filepath.Join(homeDir, ".local/share/bash-completion/completions", argname)
|
||||||
if shell.Exists(filename) {
|
if shell.Exists(filename) {
|
||||||
log.Println(filename, "file already exists")
|
log.Println(filename, "file already exists")
|
||||||
os.Exit(0)
|
// os.Exit(0)
|
||||||
}
|
}
|
||||||
basedir, _ := filepath.Split(filename)
|
basedir, _ := filepath.Split(filename)
|
||||||
if !shell.IsDir(basedir) {
|
if !shell.IsDir(basedir) {
|
||||||
|
@ -215,7 +215,7 @@ func parseArgv(argname string) *Auto {
|
||||||
}
|
}
|
||||||
|
|
||||||
// also try to parse/send cur (?)
|
// also try to parse/send cur (?)
|
||||||
func Bash2(argname string, autocomplete func(*Auto)) {
|
func Bash2(argname string, autocomplete func(*Auto)) *Auto {
|
||||||
newauto := parseArgv(argname)
|
newauto := parseArgv(argname)
|
||||||
if newauto.SetupAuto {
|
if newauto.SetupAuto {
|
||||||
// --bash was passed. try to configure bash-completion
|
// --bash was passed. try to configure bash-completion
|
||||||
|
@ -239,4 +239,5 @@ func Bash2(argname string, autocomplete func(*Auto)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
arg.Register(&argBash)
|
arg.Register(&argBash)
|
||||||
|
return newauto
|
||||||
}
|
}
|
||||||
|
|
32
bash.orig.go
32
bash.orig.go
|
@ -13,35 +13,32 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var argBash ArgsBash
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This struct can be used with the go-arg package. These
|
This struct can be used with the go-arg package. These
|
||||||
are the generic default command line arguments for the 'GUI' package
|
are the generic default command line arguments for the 'GUI' package
|
||||||
*/
|
*/
|
||||||
|
var argBash ArgsBash
|
||||||
|
|
||||||
type ArgsBash struct {
|
type ArgsBash struct {
|
||||||
Bash bool `arg:"--bash" help:"generate bash completion"`
|
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
|
id int // should be unique
|
||||||
hidden bool // don't update the toolkits when it's hidden
|
hidden bool // don't update the toolkits when it's hidden
|
||||||
Auto func([]string)
|
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
|
// 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" {
|
if len(os.Args) > 1 && os.Args[1] == "--bash" {
|
||||||
doBash(argname)
|
doBash(argname)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -54,11 +51,8 @@ func Bash(argname string, autocomplete func([]string)) *BashAuto {
|
||||||
|
|
||||||
arg.Register(&argBash)
|
arg.Register(&argBash)
|
||||||
|
|
||||||
myBash = new(BashAuto)
|
|
||||||
myBash.appName = argname
|
|
||||||
|
|
||||||
// parse go.Arg here?
|
// parse go.Arg here?
|
||||||
return myBash
|
return myAuto
|
||||||
}
|
}
|
||||||
|
|
||||||
// print out auto complete debugging info
|
// 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
|
// returns the name of the executable registered for shell autocomplete
|
||||||
func AppName() string {
|
func AppName() string {
|
||||||
return myBash.appName
|
return myAuto.appName
|
||||||
}
|
}
|
||||||
|
|
||||||
// makes a bash autocomplete file for your command
|
// makes a bash autocomplete file for your command
|
||||||
|
|
Loading…
Reference in New Issue