diff --git a/git/git.go b/git/git.go new file mode 100644 index 0000000..07261bc --- /dev/null +++ b/git/git.go @@ -0,0 +1,48 @@ +package git + +import ( + "fmt" + + Z "github.com/rwxrob/bonzai/z" + "github.com/rwxrob/help" + "github.com/rwxrob/term" + "github.com/rwxrob/to" +) + +func tags() ([]string, error) { + lines := to.Lines(Z.Out("git", "tag")) + return lines, nil +} + +func deltag(tag string) error { + if err := Z.Exec(`git`, `push`, `--delete`, `origin`, tag); err != nil { + return err + } + return Z.Exec(`git`, `tag`, `--delete`, tag) +} + +var Cmd = &Z.Cmd{ + Name: `git`, + Summary: `git extensions`, + Commands: []*Z.Cmd{help.Cmd, delTagsCmd}, +} + +var delTagsCmd = &Z.Cmd{ + Name: `deltags`, + Summary: `delete all local and remote tags`, + Commands: []*Z.Cmd{help.Cmd}, + Call: func(_ *Z.Cmd, args ...string) error { + lines, err := tags() + if err != nil { + return err + } + fmt.Println(lines) + if term.Prompt("Really delete them all? (y/N) ") != "y" { + return nil + } + for _, tag := range lines { + deltag(tag) + } + return err + }, +} diff --git a/go.go b/go.go deleted file mode 100644 index 79d48f3..0000000 --- a/go.go +++ /dev/null @@ -1,142 +0,0 @@ -package main - -import ( - "fmt" - "log" - "os" - "strings" - - Z "github.com/rwxrob/bonzai/z" - "github.com/rwxrob/fs/dir" - "github.com/rwxrob/fs/file" - "github.com/rwxrob/help" - "github.com/rwxrob/term" - "gopkg.in/yaml.v3" -) - -var golang = &Z.Cmd{ - Name: `go`, - Summary: `go related helper actions`, - MinArgs: 1, - Commands: []*Z.Cmd{help.Cmd, gowork, genisrune, sh2slice, godist}, -} - -var gowork = &Z.Cmd{ - Name: `work`, - Summary: `turn on or off go.work file`, - Usage: `(on|off)`, - MinArgs: 1, - Params: []string{"on", "off"}, - Commands: []*Z.Cmd{help.Cmd}, - Call: func(x *Z.Cmd, args ...string) error { - switch args[0] { - case "on": - if file.Exists("go.work.off") { - log.Print("go.work.off -> go.work") - return os.Rename("go.work.off", "go.work") - } - case "off": - if file.Exists("go.work") { - log.Print("go.work -> go.work.off") - return os.Rename("go.work", "go.work.off") - } - default: - return x.UsageError() - } - return nil - }, -} - -var genisrune = &Z.Cmd{ - Name: `genisrune`, - Summary: `generate a performant rune check condition`, - Commands: []*Z.Cmd{help.Cmd}, - MinArgs: 1, - Call: func(x *Z.Cmd, args ...string) error { - var conds []string - for _, r := range args[0] { - conds = append(conds, fmt.Sprintf("r==%q", r)) - } - fmt.Println(strings.Join(conds, "||")) - return nil - }, -} - -var sh2slice = &Z.Cmd{ - Name: `sh2slice`, - Summary: `splits a shell command into arguments`, - Commands: []*Z.Cmd{help.Cmd}, - Call: func(_ *Z.Cmd, args ...string) error { - list := []string{} - if len(args) == 0 { - args = append(args, term.Read()) - } - for _, a := range args { - // FIXME add awareness or globs and quoted segments - for _, aa := range strings.Fields(a) { - list = append(list, fmt.Sprintf("%q", aa)) - } - } - fmt.Println(strings.Join(list, ",")) - return nil - }, -} - -func _build(args ...string) error { - a := []string{`go`, `build`} - a = append(a, args...) - return Z.Exec(a...) -} - -var godist = &Z.Cmd{ - Name: `dist`, - Summary: `go distribution related commands`, - Commands: []*Z.Cmd{godistbuild}, -} - -type GoBuildParams struct { - Targets []GoBuildTarget - O map[string]any `yaml:",inline"` -} - -type GoBuildTarget struct { - OS string - Arch []string -} - -var godistbuild = &Z.Cmd{ - Name: `build`, - Summary: `build for for multiple architectures into dist dir`, - Commands: []*Z.Cmd{help.Cmd}, - Description: ` - This build looks for a build.yaml file in the current directory - and runs the build command on each building them all concurrently - into the *dist* directory where they are ready for upload to - GitHub as a release. Just add a README.md and run release. - `, - Call: func(_ *Z.Cmd, args ...string) error { - if !file.Exists(`build.yaml`) { - return _build(args...) - } - buf, err := os.ReadFile(`build.yaml`) - if err != nil { - return err - } - p := new(GoBuildParams) - if err := yaml.Unmarshal(buf, p); err != nil { - return err - } - os.RemoveAll(`dist`) - dir.Create(`dist`) - for _, target := range p.Targets { - for _, arch := range target.Arch { - log.Printf("Building for %v/%v", target.OS, arch) - name := fmt.Sprintf("%v_%v_%v", dir.Name(), target.OS, arch) - os.Setenv(`GOOS`, target.OS) - os.Setenv(`GOARCH`, arch) - _build(`-o`, `dist/`+name) - } - } - return nil - }, -} diff --git a/go.work.off b/go.work.off deleted file mode 100644 index 4eaf037..0000000 --- a/go.work.off +++ /dev/null @@ -1,24 +0,0 @@ -go 1.19 - -use ( - . - ../bonzai - ../compcmd - ../conf - ../fn - ../fs - ../github - ../help - ../json - ../pomo - ../scan - ../term - ../to - ../twitch - ../uniq - ../update - ../vars - ../web - ../y2j - ../yq -) diff --git a/main.go b/main.go index 4089aff..72d10e6 100644 --- a/main.go +++ b/main.go @@ -2,10 +2,10 @@ package main import ( "log" - "text/template" Z "github.com/rwxrob/bonzai/z" "github.com/rwxrob/conf" + "github.com/rwxrob/goutil" "github.com/rwxrob/help" "github.com/rwxrob/pomo" "github.com/rwxrob/twitch" @@ -13,8 +13,15 @@ import ( "github.com/rwxrob/vars" "github.com/rwxrob/y2j" "github.com/rwxrob/yq" + "github.com/rwxrob/z/git" + "github.com/rwxrob/z/tmux" ) +func init() { + Z.Dynamic["uname"] = func() string { return Z.Out("uname", "-a") } + Z.Dynamic["ls"] = func() string { return Z.Out("ls", "-l", "-h") } +} + func main() { // remove log prefixes @@ -48,7 +55,6 @@ func main() { var Cmd = &Z.Cmd{ Name: `z`, Summary: `rwxrob's bonzai command tree`, - Version: `v0.4.0`, Copyright: `Copyright 2021 Robert S Muhlestein`, License: `Apache-2.0`, Site: `rwxrob.tv`, @@ -56,15 +62,16 @@ var Cmd = &Z.Cmd{ Issues: `github.com/rwxrob/z/issues`, Commands: []*Z.Cmd{ - help.Cmd, conf.Cmd, vars.Cmd, y2j.Cmd, twitch.Cmd, tmux, yq.Cmd, golang, - uniq.Cmd, pomo.Cmd, //github.Cmd, //update.Cmd, + help.Cmd, conf.Cmd, vars.Cmd, + y2j.Cmd, twitch.Cmd, tmux.Cmd, yq.Cmd, goutil.Cmd, + uniq.Cmd, pomo.Cmd, git.Cmd, //github.Cmd, //update.Cmd, }, Shortcuts: Z.ArgMap{ "project": {"twitch", "bot", "commands", "edit", "project"}, "status": {"tmux", "update"}, "offscreen": {"chat", "!offscreen"}, - "commands": {"twitch", "bot", "commands", "file", "edit"}, + "info": {"twitch", "bot", "commands", "file", "edit"}, "sync": {"twitch", "bot", "commands", "sync"}, "work": {"go", "work"}, "chat": {"twitch", "chat"}, @@ -75,17 +82,12 @@ var Cmd = &Z.Cmd{ "epoch": {"uniq", "second"}, }, - Dynamic: template.FuncMap{ - "uname": func() string { return Z.Out("uname", "-a") }, - "ls": func() string { return Z.Out("ls", "-l", "-h") }, - }, - Description: ` - Hi, I'm rwxrob.tv and this is my Bonzai™ tree. I am slowly - replacing all my shell scripts and other Go utilities with Bonzai - branches that I graft into this {{cmd .Name}} command. You are welcome - to play around with it, but please know that I am radically changing - things *daily*. + Hi, I'm rwxrob.tv and this {{cmd .Name }} is my Bonzai™ tree. I am + slowly replacing all my shell scripts and other Go utilities with + Bonzai branches that I graft into this {{cmd .Name}} command. You + are welcome to play around with it, but please know that I am + radically changing things *daily*. Also check out https://github.com/rwxrob/foo for a sample template Bonzai tree to get started on your own. diff --git a/tmux.go b/tmux/tmux.go similarity index 86% rename from tmux.go rename to tmux/tmux.go index 41e8fcb..52ba15f 100644 --- a/tmux.go +++ b/tmux/tmux.go @@ -1,4 +1,4 @@ -package main +package tmux import ( "os" @@ -10,13 +10,13 @@ import ( "github.com/rwxrob/vars" ) -var tmux = &Z.Cmd{ +var Cmd = &Z.Cmd{ Name: `tmux`, Summary: `make tmux updates`, - Commands: []*Z.Cmd{help.Cmd, tmuxUpdate, vars.Cmd, in}, + Commands: []*Z.Cmd{help.Cmd, vars.Cmd, updateCmd, inCmd}, } -var in = &Z.Cmd{ +var inCmd = &Z.Cmd{ Name: `in`, Summary: `exec a nested tmux session (unset TMUX)`, Usage: `[help|...]`, @@ -35,7 +35,7 @@ var in = &Z.Cmd{ }, } -var tmuxUpdate = &Z.Cmd{ +var updateCmd = &Z.Cmd{ Name: `update`, Summary: `update the onscreen status`, Call: func(_ *Z.Cmd, args ...string) error {