summaryrefslogtreecommitdiff
path: root/args.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2018-10-19 20:18:15 +0300
committerGitHub <[email protected]>2018-10-19 20:18:15 +0300
commitffc2cf5e958af5ac4156a886153c7cadd24a521a (patch)
tree1b4936b7ce044bd52e1ae3f9e4cf7c41a2a89a35 /args.go
parent0d98d7ee195f007b3453c002780ed80c76e7c806 (diff)
parent5fdb1adfd7447867ac25c2dbafbe577ccc6d9e7f (diff)
Merge pull request #73 from posener/point
Add support for CMP_POINT
Diffstat (limited to 'args.go')
-rw-r--r--args.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/args.go b/args.go
index 1ba4d69..17ab2c6 100644
--- a/args.go
+++ b/args.go
@@ -57,11 +57,20 @@ func newArgs(line string) Args {
}
}
+// 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.
func splitFields(line string) []string {
parts := strings.Fields(line)
+
+ // Add empty field if the last field was completed.
if len(line) > 0 && unicode.IsSpace(rune(line[len(line)-1])) {
parts = append(parts, "")
}
+
+ // Treat the last field if it is of the form "a=b"
parts = splitLastEqual(parts)
return parts
}