-// RunShellCommand executes a shell command and returns the output/error
-func RunShellCommand(input string) (string, error) {
- inputCmd := SplitCommandArgs(input)[0]
- args := SplitCommandArgs(input)[1:]
-
- cmd := exec.Command(inputCmd, args...)
- outputBytes := &bytes.Buffer{}
- cmd.Stdout = outputBytes
- cmd.Stderr = outputBytes
- cmd.Start()
- err := cmd.Wait() // wait for command to finish
- outstring := outputBytes.String()
- return outstring, err
-}
-
-// HandleShellCommand runs the shell command
-// The openTerm argument specifies whether a terminal should be opened (for viewing output
-// or interacting with stdin)
-func HandleShellCommand(input string, openTerm bool, waitToFinish bool) string {
- inputCmd := SplitCommandArgs(input)[0]
- if !openTerm {
- // Simply run the command in the background and notify the user when it's done
- messenger.Message("Running...")
- go func() {
- output, err := RunShellCommand(input)
- totalLines := strings.Split(output, "\n")
-
- if len(totalLines) < 3 {
- if err == nil {
- messenger.Message(inputCmd, " exited without error")
- } else {
- messenger.Message(inputCmd, " exited with error: ", err, ": ", output)
- }
- } else {
- messenger.Message(output)
- }
- // We have to make sure to redraw
- RedrawAll()
- }()
+// Term opens a terminal in the current view
+func Term(args []string) {
+ var err error
+ if len(args) == 0 {
+ err = CurView().StartTerminal([]string{os.Getenv("SHELL"), "-i"}, true, false, "")