func splitFields(line string) []string {
	parts := strings.Fields(line)
	if len(line) > 0 && unicode.IsSpace(rune(line[len(line)-1])) {
		parts = append(parts, "")
	}
	parts = splitLastEqual(parts)
	return parts
}
splitFields returns a list of fields from the given command line.
If the last character is space, it appends an empty field in the end
indicating that the field before it was completed.
If the last field is of the form "a=b", it splits it to two fields: "a", "b",
So it can be completed.
package complete
import (
	"os"
	"path/filepath"
	"strings"
	"unicode"
)
type Args struct {
	All []string
	Completed []string
	Last string
	LastCompleted string
}
func (a Args) Directory() string {
	if info, err := os.Stat(a.Last); err == nil && info.IsDir() {
		return fixPathForm(a.Last, a.Last)
	}
	dir := filepath.Dir(a.Last)
	if info, err := os.Stat(dir); err != nil || !info.IsDir() {
		return "./"
	}
	return fixPathForm(a.Last, dir)
}
func newArgs(line string) Args {
	var (
		all       []string
		completed []string
	)
	parts := splitFields(line)
	if len(parts) > 0 {
		all = parts[1:]
		completed = removeLast(parts[1:])
	}
	return Args{
		All:           all,
		Completed:     completed,
		Last:          last(parts),
		LastCompleted: last(completed),
	}
}