X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=internal%2Fshell%2Fshell.go;h=53bf67ce4215616b9ef3ba188baf84fe1d9de5d9;hb=d65285ee54ede55d5196699fc571ace94a720fde;hp=3a00a30f5dbf91293a7fa54378658ee15b4ecb60;hpb=93431a9ddf819d801031d5751dafd9b1ce515641;p=micro.git diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 3a00a30f..53bf67ce 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -2,6 +2,7 @@ package shell import ( "bytes" + "errors" "fmt" "io" "os" @@ -9,8 +10,8 @@ import ( "os/signal" "strings" + shellquote "github.com/kballard/go-shellquote" "github.com/zyedidia/micro/internal/screen" - "github.com/zyedidia/micro/pkg/shellwords" ) // 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