From 5787582c2e6a69deb0a45743a7af1a7d8f238c08 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Fri, 31 Dec 2021 14:11:11 -0400 Subject: [PATCH] fix: expansion on quotes in alias expansion to show what this fixes: `git commit -m "a commit message"` would report that it didnt find pathspecs for commit or message, because the commit message is only passed as `a` also fixes it to make it work in commands in other sh syntax --- shell.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/shell.go b/shell.go index eb14b4c..2c06537 100644 --- a/shell.go +++ b/shell.go @@ -9,6 +9,7 @@ import ( "time" "github.com/yuin/gopher-lua" + "mvdan.cc/sh/v3/shell" //"github.com/yuin/gopher-lua/parse" "mvdan.cc/sh/v3/interp" "mvdan.cc/sh/v3/syntax" @@ -85,10 +86,19 @@ func execCommand(cmd string) error { exechandle := func(ctx context.Context, args []string) error { _, argstring := splitInput(strings.Join(args, " ")) + // i dont really like this but it works + if aliases.All()[args[0]] != "" { + for i, arg := range args { + if strings.Contains(arg, " ") { + args[i] = fmt.Sprintf("\"%s\"", arg) + } + } + _, argstring = splitInput(strings.Join(args, " ")) - // If alias was found, use command alias - argstring = aliases.Resolve(argstring) - args, _ = splitInput(argstring) + // If alias was found, use command alias + argstring = aliases.Resolve(argstring) + args, _ = shell.Fields(argstring, nil) + } // If command is defined in Lua then run it luacmdArgs := l.NewTable()