mirror of
https://github.com/Rudi9719/kbtui.git
synced 2026-03-22 09:57:24 +00:00
55
cmdExec.go
Normal file
55
cmdExec.go
Normal file
@ -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))
|
||||||
|
}
|
||||||
@ -44,6 +44,7 @@ func cmdJoin(cmd []string) {
|
|||||||
printInfoF("You are joining: $TEXT", config.Colors.Message.LinkKeybase.stylize(joinedName))
|
printInfoF("You are joining: $TEXT", config.Colors.Message.LinkKeybase.stylize(joinedName))
|
||||||
clearView("Chat")
|
clearView("Chat")
|
||||||
setViewTitle("Input", fmt.Sprintf(" %s ", joinedName))
|
setViewTitle("Input", fmt.Sprintf(" %s ", joinedName))
|
||||||
|
lastChat = joinedName
|
||||||
go populateChat()
|
go populateChat()
|
||||||
default:
|
default:
|
||||||
printInfo(fmt.Sprintf("To join a team use %sjoin <team> <channel>", config.Basics.CmdPrefix))
|
printInfo(fmt.Sprintf("To join a team use %sjoin <team> <channel>", config.Basics.CmdPrefix))
|
||||||
|
|||||||
2
mage.go
2
mage.go
@ -93,7 +93,7 @@ func BuildAllCommandsT() {
|
|||||||
// Build kbtui with beta functionality
|
// Build kbtui with beta functionality
|
||||||
func BuildBeta() {
|
func BuildBeta() {
|
||||||
mg.Deps(getRemotePackages)
|
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() {
|
defer func() {
|
||||||
exit(err)
|
exit(err)
|
||||||
}()
|
}()
|
||||||
|
|||||||
8
main.go
8
main.go
@ -22,6 +22,7 @@ var (
|
|||||||
channels []keybase.Channel
|
channels []keybase.Channel
|
||||||
stream = false
|
stream = false
|
||||||
lastMessage keybase.ChatAPI
|
lastMessage keybase.ChatAPI
|
||||||
|
lastChat = ""
|
||||||
g *gocui.Gui
|
g *gocui.Gui
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -124,6 +125,13 @@ func initKeybindings() error {
|
|||||||
}); err != nil {
|
}); err != nil {
|
||||||
return err
|
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,
|
if err := g.SetKeybinding("Edit", gocui.KeyCtrlC, gocui.ModNone,
|
||||||
func(g *gocui.Gui, v *gocui.View) error {
|
func(g *gocui.Gui, v *gocui.View) error {
|
||||||
popupView("Chat")
|
popupView("Chat")
|
||||||
|
|||||||
Reference in New Issue
Block a user