diff --git a/go.mod b/go.mod index fc55132..997f181 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,6 @@ go 1.13 require ( github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 gopkg.in/alecthomas/kingpin.v2 v2.2.6 ) diff --git a/go.sum b/go.sum index edf4012..7c3aee4 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/selector.go b/selector.go index a4a285c..ffe8b03 100644 --- a/selector.go +++ b/selector.go @@ -7,9 +7,11 @@ import ( "os/exec" "strconv" "strings" + + "github.com/kballard/go-shellquote" ) -func selector(data []string, max int, tool string, prompt string, toolsArgs string) (string, error) { +func selector(data []string, max int, tool string, prompt string, toolArgs string) (string, error) { if len(data) == 0 { return "", errors.New("nothing to show: no data available") } @@ -46,7 +48,13 @@ func selector(data []string, max int, tool string, prompt string, toolsArgs stri return "", fmt.Errorf("unsupported tool: %s", tool) } - args = append(args, strings.Fields(toolsArgs)...) + if len(toolArgs) > 0 { + targs, err := shellquote.Split(toolArgs) + if err != nil { + return "", fmt.Errorf("selector: %w", err) + } + args = append(args, targs...) + } processed, guide := preprocessData(data, true, false)