]> git.lizzy.rs Git - micro.git/blobdiff - internal/shell/shell.go
Merge
[micro.git] / internal / shell / shell.go
index 3a00a30f5dbf91293a7fa54378658ee15b4ecb60..f5871c794d9c7115e5149105edcb5be3c1d81d22 100644 (file)
@@ -2,6 +2,7 @@ package shell
 
 import (
        "bytes"
+       "errors"
        "fmt"
        "io"
        "os"
@@ -9,8 +10,8 @@ import (
        "os/signal"
        "strings"
 
-       "github.com/zyedidia/micro/internal/screen"
-       "github.com/zyedidia/micro/pkg/shellwords"
+       shellquote "github.com/kballard/go-shellquote"
+       "github.com/zyedidia/micro/v2/internal/screen"
 )
 
 // ExecCommand executes a command using exec
@@ -32,10 +33,13 @@ func ExecCommand(name string, arg ...string) (string, error) {
 
 // RunCommand executes a shell command and returns the output/error
 func RunCommand(input string) (string, error) {
-       args, err := shellwords.Split(input)
+       args, err := shellquote.Split(input)
        if err != nil {
                return "", err
        }
+       if len(args) == 0 {
+               return "", errors.New("No arguments")
+       }
        inputCmd := args[0]
 
        return ExecCommand(inputCmd, args[1:]...)
@@ -45,10 +49,13 @@ func RunCommand(input string) (string, error) {
 // It returns a function which will run the command and returns a string
 // message result
 func RunBackgroundShell(input string) (func() string, error) {
-       args, err := shellwords.Split(input)
+       args, err := shellquote.Split(input)
        if err != nil {
                return nil, err
        }
+       if len(args) == 0 {
+               return nil, errors.New("No arguments")
+       }
        inputCmd := args[0]
        return func() string {
                output, err := RunCommand(input)
@@ -68,10 +75,13 @@ func RunBackgroundShell(input string) (func() string, error) {
 
 // RunInteractiveShell runs a shellcommand interactively
 func RunInteractiveShell(input string, wait bool, getOutput bool) (string, error) {
-       args, err := shellwords.Split(input)
+       args, err := shellquote.Split(input)
        if err != nil {
                return "", err
        }
+       if len(args) == 0 {
+               return "", errors.New("No arguments")
+       }
        inputCmd := args[0]
 
        // Shut down the screen because we're going to interact directly with the shell