diff --git a/cmdExec.go b/cmdExec.go new file mode 100644 index 0000000..ca3e099 --- /dev/null +++ b/cmdExec.go @@ -0,0 +1,55 @@ +// +build !rm_basic_commands allcommands execcmd + +package main + +import ( + "fmt" + "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) { + outputBytes, err := k.Exec(args...) + 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, " "))) + output := string(outputBytes) + printToView("Chat", fmt.Sprintf("%s", output)) + } +} + +func printExecHelp() { + printInfo(fmt.Sprintf("To execute a keybase command use %sexec ", config.Basics.CmdPrefix)) +} 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)) 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) }() 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")