diff --git a/cmd/micro/command.go b/cmd/micro/command.go index 7fcf41d6..faed87f4 100644 --- a/cmd/micro/command.go +++ b/cmd/micro/command.go @@ -2,10 +2,28 @@ package main import ( "os" + "os/exec" "regexp" "strings" ) +func HandleShellCommand(input string, view *View) { + inputCmd := strings.Split(input, " ")[0] + args := strings.Split(input, " ")[1:] + + // Execute Command + cmdout := exec.Command(inputCmd, args...) + output, err := cmdout.Output() + if err != nil { + messenger.Error("Error: " + err.Error()) + return + } + + // Display last line of output + messenger.Message(string(output)) + +} + // HandleCommand handles input from the user func HandleCommand(input string, view *View) { inputCmd := strings.Split(input, " ")[0] diff --git a/cmd/micro/messenger.go b/cmd/micro/messenger.go index bb30ba2f..ff164c3b 100644 --- a/cmd/micro/messenger.go +++ b/cmd/micro/messenger.go @@ -3,9 +3,10 @@ package main import ( "bufio" "fmt" - "github.com/gdamore/tcell" "os" "strconv" + + "github.com/gdamore/tcell" ) // TermMessage sends a message to the user in the terminal. This usually occurs before diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 6dbdb76a..962d8959 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -2,13 +2,14 @@ package main import ( "fmt" + "io/ioutil" + "os" + "github.com/gdamore/tcell" "github.com/gdamore/tcell/encoding" "github.com/go-errors/errors" "github.com/mattn/go-isatty" "github.com/mitchellh/go-homedir" - "io/ioutil" - "os" ) const ( @@ -200,6 +201,11 @@ func main() { if !canceled { HandleCommand(input, view) } + case tcell.KeyCtrlB: + input, canceled := messenger.Prompt("$ ") + if !canceled { + HandleShellCommand(input, view) + } case tcell.KeyCtrlG: DisplayHelp() // Make sure to resize the view if the user resized the terminal while looking at the help text