From e60f65d59cbd99f54d1625667a65cad4532e183f Mon Sep 17 00:00:00 2001 From: David Haukeness Date: Tue, 29 Oct 2019 13:53:25 -0600 Subject: [PATCH 1/5] updated to remove old emoji and add execcmd --- mage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mage.go b/mage.go index fef71a6..554c3aa 100644 --- a/mage.go +++ b/mage.go @@ -93,7 +93,7 @@ func BuildAllCommandsT() { // Build kbtui with beta functionality func BuildBeta() { mg.Deps(getRemotePackages) - if err := sh.Run("go", "build", "-tags", "allcommands showreactionscmd emojiList tabcompletion"); err != nil { + if err := sh.Run("go", "build", "-tags", "allcommands showreactionscmd tabcompletion execcmd"); err != nil { defer func() { exit(err) }() From f890a6e56c2467c952ffce554456ce4a9592594e Mon Sep 17 00:00:00 2001 From: David Haukeness Date: Tue, 29 Oct 2019 15:31:00 -0600 Subject: [PATCH 2/5] added initial cmdExec --- cmdExec.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 cmdExec.go diff --git a/cmdExec.go b/cmdExec.go new file mode 100644 index 0000000..aec242d --- /dev/null +++ b/cmdExec.go @@ -0,0 +1,56 @@ +// +build !rm_basic_commands allcommands execcmd + +package main + +import ( + "fmt" + "os/exec" + "strings" +) + +func init() { + command := Command{ + Cmd: []string{"exec", "ex"}, + Description: "$keybase args - executes keybase $args and returns the output", + Help: "", + Exec: cmdExec, + } + RegisterCommand(command) +} + +func cmdExec(cmd []string) { + l := len(cmd) + switch { + case l >= 2: + if cmd[1] == "keybase" { + // if the user types /exec keybase wallet list + // only send ["wallet", "list"] + runKeybaseExec(cmd[2:]) + } else { + // send everything except the command + runKeybaseExec(cmd[1:]) + } + case l == 1: + fallthrough + default: + printExecHelp() + } +} + +func runKeybaseExec(args []string) { + cmd := exec.Command("keybase", args...) + output, err := cmd.CombinedOutput() + if err != nil { + printToView("Feed", fmt.Sprintf("Exec error: %+v", err)) + } else { + channel.Name = "" + // unjoin the chat + clearView("Chat") + setViewTitle("Input", fmt.Sprintf(" /exec %s ", strings.Join(args, " "))) + printToView("Chat", fmt.Sprintf("%s", output)) + } +} + +func printExecHelp() { + printInfo(fmt.Sprintf("To execute a keybase command use %sexec ", config.Basics.CmdPrefix)) +} From 4a7818c79e42fb3cc9e5a5176c35501ee606d1d1 Mon Sep 17 00:00:00 2001 From: David Haukeness Date: Tue, 29 Oct 2019 15:31:30 -0600 Subject: [PATCH 3/5] updated to fill in lastChat --- cmdJoin.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmdJoin.go b/cmdJoin.go index a2800d1..27e86e7 100644 --- a/cmdJoin.go +++ b/cmdJoin.go @@ -44,6 +44,7 @@ func cmdJoin(cmd []string) { printInfoF("You are joining: $TEXT", config.Colors.Message.LinkKeybase.stylize(joinedName)) clearView("Chat") setViewTitle("Input", fmt.Sprintf(" %s ", joinedName)) + lastChat = joinedName go populateChat() default: printInfo(fmt.Sprintf("To join a team use %sjoin ", config.Basics.CmdPrefix)) From 5e6e97d7f6d8e7931560e651a3497755f2ec7bdd Mon Sep 17 00:00:00 2001 From: David Haukeness Date: Tue, 29 Oct 2019 15:37:01 -0600 Subject: [PATCH 4/5] updated to have lastChat var and new keybinding for CTRL+z --- main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.go b/main.go index 36ce0d7..4e300ae 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ var ( channels []keybase.Channel stream = false lastMessage keybase.ChatAPI + lastChat = "" g *gocui.Gui ) @@ -124,6 +125,13 @@ func initKeybindings() error { }); err != nil { return err } + if err := g.SetKeybinding("", gocui.KeyCtrlZ, gocui.ModNone, + func(g *gocui.Gui, v *gocui.View) error { + cmdJoin([]string{"/join", lastChat}) + return nil + }); err != nil { + return err + } if err := g.SetKeybinding("Edit", gocui.KeyCtrlC, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { popupView("Chat") From bf0c271d2a93257c0410c94dfb269b61565d6167 Mon Sep 17 00:00:00 2001 From: David Haukeness Date: Tue, 29 Oct 2019 16:01:17 -0600 Subject: [PATCH 5/5] updated to use instead of --- cmdExec.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmdExec.go b/cmdExec.go index aec242d..ca3e099 100644 --- a/cmdExec.go +++ b/cmdExec.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "os/exec" "strings" ) @@ -38,8 +37,7 @@ func cmdExec(cmd []string) { } func runKeybaseExec(args []string) { - cmd := exec.Command("keybase", args...) - output, err := cmd.CombinedOutput() + outputBytes, err := k.Exec(args...) if err != nil { printToView("Feed", fmt.Sprintf("Exec error: %+v", err)) } else { @@ -47,6 +45,7 @@ func runKeybaseExec(args []string) { // unjoin the chat clearView("Chat") setViewTitle("Input", fmt.Sprintf(" /exec %s ", strings.Join(args, " "))) + output := string(outputBytes) printToView("Chat", fmt.Sprintf("%s", output)) } }