Browse Source

Merge pull request #36 from haukened/dev

Adding `/exec` functionality
pull/37/head
Gregory Rudolph 5 years ago committed by GitHub
parent
commit
4ac523e7f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 55
      cmdExec.go
  2. 1
      cmdJoin.go
  3. 2
      mage.go
  4. 8
      main.go

55
cmdExec.go

@ -0,0 +1,55 @@ @@ -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 <keybase args>", config.Basics.CmdPrefix))
}

1
cmdJoin.go

@ -44,6 +44,7 @@ func cmdJoin(cmd []string) { @@ -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 <team> <channel>", config.Basics.CmdPrefix))

2
mage.go

@ -93,7 +93,7 @@ func BuildAllCommandsT() { @@ -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)
}()

8
main.go

@ -22,6 +22,7 @@ var ( @@ -22,6 +22,7 @@ var (
channels []keybase.Channel
stream = false
lastMessage keybase.ChatAPI
lastChat = ""
g *gocui.Gui
)
@ -124,6 +125,13 @@ func initKeybindings() error { @@ -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")

Loading…
Cancel
Save