From 7bf204299f01a0739c435d3768277c279c6291d3 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 25 Sep 2025 02:09:19 -0500 Subject: new bash autocomplete --- argv.go | 25 +++++++++++++++---------- build | 4 ++++ main.go | 6 ++---- structs.go | 3 +-- 4 files changed, 22 insertions(+), 16 deletions(-) create mode 100755 build diff --git a/argv.go b/argv.go index 50936c0..727a063 100644 --- a/argv.go +++ b/argv.go @@ -4,8 +4,9 @@ package main import ( - "fmt" "os" + + "go.wit.com/lib/gui/prep" ) /* @@ -42,15 +43,19 @@ and with the right geometries. TODO: restore the bash working paths ` } -func (a args) DoAutoComplete(argv []string) { - switch argv[0] { - case "dump": - fmt.Println("--terminals") - default: - if argv[0] == ARGNAME { - // list the subcommands here - fmt.Println("--restore save dump dumpx list") - } +/* + handles shell autocomplete +*/ + +func (args) Appname() string { + return ARGNAME +} + +func (a args) DoAutoComplete(pb *prep.Auto) { + if pb.Cmd == "" { + pb.Autocomplete3([]string{"--restore", "save", "dump", "dumpx", "list"}) + } else { + pb.SubCommand(pb.Argv...) } os.Exit(0) } diff --git a/build b/build new file mode 100755 index 0000000..73061de --- /dev/null +++ b/build @@ -0,0 +1,4 @@ +#!/bin/bash -x + +mkdir -p files/usr/share/bash-completion/completions/ +startxplacement --bash > files/usr/share/bash-completion/completions/startxplacement diff --git a/main.go b/main.go index d2bebf7..9b7bacd 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ package main import ( "fmt" - "go.wit.com/dev/alexflint/arg" "go.wit.com/lib/gui/prep" "go.wit.com/log" ) @@ -27,9 +26,8 @@ var configFile string = "/home/jcarr/.config/startxplacement.out" func main() { me = new(mainType) - prep.Bash(ARGNAME, argv.DoAutoComplete) // todo: this line should be: prep.Bash(argv) - me.myGui = prep.Gui() // prepares the GUI package for go-args - me.pp = arg.MustParse(&argv) + me.myGui = prep.Gui() // prepares the GUI package for go-args + me.auto = prep.Bash3(&argv) // add support for bash autocomplete with go-arg if argv.DumpX != nil { doDumpX() diff --git a/structs.go b/structs.go index 6251719..42b51c8 100644 --- a/structs.go +++ b/structs.go @@ -4,7 +4,6 @@ package main import ( - "go.wit.com/dev/alexflint/arg" "go.wit.com/lib/gui/prep" ) @@ -12,6 +11,6 @@ var me *mainType // this app's variables type mainType struct { - pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + auto *prep.Auto // more experiments for bash handling myGui *prep.GuiPrep // the gui toolkit handle } -- cgit v1.2.3