Repository: rsteube/carapace
Pull request #842 (2023-07-26 11:43:49)

added Action.Split


Patch:
diff --git a/action.go b/action.go
index 323b100..c29f0f7 100644
--- a/action.go
+++ b/action.go
@@ -9,6 +9,7 @@ import (
 
 	"github.com/rsteube/carapace/internal/cache"
 	"github.com/rsteube/carapace/internal/common"
+	"github.com/rsteube/carapace/internal/lexer"
 	pkgcache "github.com/rsteube/carapace/pkg/cache"
 	"github.com/rsteube/carapace/pkg/style"
 )
@@ -294,3 +295,32 @@ func (a Action) UsageF(f func() string) Action {
 		return a
 	})
 }
+
+// Split splits `Context.Value` using a shell lexer.
+func (a Action) Split() Action {
+	return ActionCallback(func(c Context) Action {
+		tokenset, err := lexer.Split(c.Value)
+		if err != nil {
+			return ActionMessage(err.Error())
+		}
+
+		c.Args = tokenset.Tokens[:len(tokenset.Tokens)-1]
+		c.Parts = []string{}
+		c.Value = tokenset.Tokens[len(tokenset.Tokens)-1]
+		invoked := a.Invoke(c)
+		for index, value := range invoked.rawValues {
+			if !invoked.meta.Nospace.Matches(value.Value) {
+				switch tokenset.State {
+				case lexer.OPEN_DOUBLE:
+					invoked.rawValues[index].Value = fmt.Sprintf(`"%v" `, strings.Replace(value.Value, `"`, `\"`, -1))
+				case lexer.OPEN_SINGLE:
+					invoked.rawValues[index].Value = fmt.Sprintf(`'%v' `, strings.Replace(value.Value, `'`, `'"'"'`, -1))
+				default:
+					invoked.rawValues[index].Value = strings.Replace(value.Value, ` `, `\ `, -1) + ` `
+				}
+			}
+		}
+		invoked.Prefix(tokenset.Prefix)
+		return invoked.ToA().NoSpace()
+	})
+}
diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md
index 04d999a..7e297d4 100644
--- a/docs/src/SUMMARY.md
+++ b/docs/src/SUMMARY.md
@@ -17,6 +17,7 @@
     - [Prefix](./carapace/action/prefix.md)
     - [Retain](./carapace/action/retain.md)
     - [Shift](./carapace/action/shift.md)
+    - [Split](./carapace/action/split.md)
     - [Style](./carapace/action/style.md)
     - [StyleF](./carapace/action/styleF.md)
     - [StyleR](./carapace/action/styleR.md)
diff --git a/docs/src/carapace/action/split.cast b/docs/src/carapace/action/split.cast
new file mode 100644
index 0000000..89f2997
--- /dev/null
+++ b/docs/src/carapace/action/split.cast
@@ -0,0 +1,93 @@
+{"version": 2, "width": 108, "height": 24, "timestamp": 1690393669, "env": {"SHELL": "elvish", "TERM": "tmux-256color"}}
+[0.079721, "o", "\u001b[?7h\u001b[7m⏎\u001b[m                                                                                                           \r \r\u001b[?7l\u001b[?2004h\u001b[?25l\r???>                                                                                                   ???> \r\u001b[5C\u001b[?25h"]
+[0.080283, "o", "\u001b[?25l\r\u001b[5C\u001b[K\r\u001b[5C\u001b[?25h"]
+[0.093223, "o", "\u001b[?25l\r\r\u001b[5C\u001b[?25h\u001b[?25l\r\r\u001b[5C\u001b[?25h"]
+[0.093351, "o", "\u001b[?25l\r\u001b[K\r\n\u001b[0;1;36mcarapace/example\u001b[0;m on \u001b[0;1;35m add-action-split\u001b[0;m \u001b[0;1;31m[$!?]\u001b[0;m via \u001b[0;1;36m🐹 v1.20.6 \r\n\u001b[0;1;37mesh\u001b[0;m \u001b[0;1;32m❯\u001b[0;m \r\u001b[6C\u001b[?25h"]
+[0.285229, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[0;31me\u001b[0;m\r\u001b[7C\u001b[?25h"]
+[0.285893, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"]
+[0.30013, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"]
+[0.300359, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"]
+[0.467286, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[7C\u001b[0;31mx\u001b[0;m\r\u001b[8C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[8C\u001b[?25h"]
+[0.621171, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\u001b[0;32mexa\u001b[0;m\r\u001b[9C\u001b[?25h"]
+[0.621252, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[9C\u001b[?25h"]
+[0.775825, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\u001b[0;31mexam\u001b[0;m\r\u001b[10C\u001b[?25h"]
+[0.775894, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[10C\u001b[?25h"]
+[0.829007, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[10C\u001b[0;31mp\u001b[0;m\r\u001b[11C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[11C\u001b[?25h"]
+[0.936611, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[11C\u001b[0;31ml\u001b[0;m\r\u001b[12C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[12C\u001b[?25h"]
+[0.939717, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[12C\u001b[?25h"]
+[0.93993, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[12C\u001b[?25h"]
+[0.939976, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[12C\u001b[?25h"]
+[1.051556, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\u001b[0;32mexample\u001b[0;m\r\u001b[13C\u001b[?25h"]
+[1.051656, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[13C\u001b[?25h"]
+[1.12868, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[13C \r\u001b[14C\u001b[?25h"]
+[1.283721, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[14Cm\r\u001b[15C\u001b[?25h"]
+[1.283829, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[15C\u001b[?25h"]
+[1.353808, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[15Co\r\u001b[16C\u001b[?25h"]
+[1.353868, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[16C\u001b[?25h"]
+[1.44018, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[16Cdifier \r\u001b[23C\u001b[?25h"]
+[1.835434, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[23C-\r\u001b[24C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[24C\u001b[?25h"]
+[1.985903, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[24C-\r\u001b[25C\u001b[?25h"]
+[2.051977, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[25Cs\r\u001b[26C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[26C\u001b[?25h"]
+[2.163353, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[26Cp\r\u001b[27C\u001b[?25h"]
+[2.163441, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[27C\u001b[?25h"]
+[2.297944, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[27Clit \r\u001b[31C\u001b[?25h"]
+[2.641372, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[0;33m'pos\u001b[0;m\r\u001b[35C\u001b[?25h"]
+[3.040589, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'pos1 '\r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7mpos1\u001b[0;m  positional1\u001b[1A\r\u001b[22C\u001b[?25h"]
+[4.038543, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[35C\u001b[K\u001b[0;4;33mitional1 '\r\n\r\n\u001b[0;m\u001b[Kpos1  \u001b[0;7mpositional1\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[4.527175, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'positional1 '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[45C\u001b[?25h"]
+[4.527322, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[45C\u001b[?25h"]
+[5.479418, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[44C\u001b[K\r\u001b[44C\u001b[?25h"]
+[5.564789, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[44C\u001b[0;33m-\u001b[0;m\r\u001b[45C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[45C\u001b[?25h"]
+[6.167136, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[44C\u001b[K\r\u001b[44C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[44C\u001b[?25h"]
+[6.608682, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[44C\u001b[0;33m-\u001b[0;m\r\u001b[45C\u001b[?25h"]
+[6.609064, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[45C\u001b[?25h"]
+[6.735337, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'positional1 --bool '\r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7m--bool\u001b[0;2;7m (bool flag)\u001b[0;m  \u001b[0;34m--string\u001b[0;2m (string flag)\u001b[0;m  -b\u001b[0;2m (bool flag)\u001b[0;m  \u001b[0;34m-s\u001b[0;2m (string flag)\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[7.470897, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'positional1 --bool '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[52C\u001b[?25h"]
+[7.47098, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[52C\u001b[?25h"]
+[7.707582, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'positional1 --bool README.md '\r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7;38;2;255;184;108mREADME.md\u001b[0;m  \u001b[0;38;2;189;147;249m_test/\u001b[0;m  \u001b[0;38;2;189;147;249mcmd/\u001b[0;m  \u001b[0;38;2;255;184;108mmain.go\u001b[0;m  \u001b[0;38;2;255;184;108mmain_test.go\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[8.647642, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\r\n\r\n\u001b[1A\r\u001b[22C\u001b[?25h"]
+[8.648114, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\r\n\r\n\u001b[1A\r\u001b[22C\u001b[?25h"]
+[8.823431, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\r\n\r\n\u001b[1A\r\u001b[22C\u001b[?25h"]
+[8.823777, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\r\n\r\n\u001b[1A\r\u001b[22C\u001b[?25h"]
+[9.357695, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'positional1 --bool '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[52C\u001b[?25h"]
+[9.73989, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[51C\u001b[K\r\u001b[51C\u001b[?25h"]
+[9.892409, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[50C\u001b[K\r\u001b[50C\u001b[?25h"]
+[10.160007, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[50C\u001b[0;33m=\u001b[0;m\r\u001b[51C\u001b[?25h"]
+[10.160086, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[51C\u001b[?25h"]
+[10.307209, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'positional1 --bool=false '\r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7;31mfalse\u001b[0;m  \u001b[0;32mtrue\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[10.996689, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[51C\u001b[K\u001b[0;4;33mtrue '\r\n\r\n\u001b[0;m\u001b[K\u001b[0;31mfalse\u001b[0;m  \u001b[0;7;32mtrue\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[11.336661, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'positional1 --bool=true '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[57C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[57C\u001b[?25h"]
+[12.46457, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[56C\u001b[K\r\u001b[56C\u001b[?25h"]
+[12.858117, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[56C\u001b[0;33m\"\u001b[0;m\r\u001b[57C\u001b[?25h"]
+[12.858221, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[57C\u001b[?25h"]
+[13.146091, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[57C\u001b[0;33m-\u001b[0;m\r\u001b[58C\u001b[?25h"]
+[13.14619, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[58C\u001b[?25h"]
+[13.334988, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[58C\u001b[0;33m-\u001b[0;m\r\u001b[59C\u001b[?25h"]
+[13.33509, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[59C\u001b[?25h"]
+[13.455233, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[59C\u001b[0;33mstring\" '\u001b[0;m\r\u001b[68C\u001b[?25h"]
+[14.299885, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'positional1 --bool=true \"--string\" one '\r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7mone\u001b[0;m  three  two\u001b[1A\r\u001b[22C\u001b[?25h"]
+[15.046595, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[67C\u001b[K\u001b[0;4;33mthree '\r\n\r\n\u001b[0;m\u001b[Kone  \u001b[0;7mthree\u001b[0;m  two\u001b[1A\r\u001b[22C\u001b[?25h"]
+[15.208427, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[68C\u001b[K\u001b[0;4;33mwo '\r\n\r\n\u001b[5C\u001b[0;m\u001b[Kthree  \u001b[0;7mtwo\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[15.696686, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'positional1 --bool=true \"--string\" two '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[72C\u001b[?25h"]
+[15.696796, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[72C\u001b[?25h"]
+[16.055887, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'positional1 --bool=true \"--string\" two README.md '\r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7;38;2;255;184;108mREADME.md\u001b[0;m  \u001b[0;38;2;189;147;249m_test/\u001b[0;m  \u001b[0;38;2;189;147;249mcmd/\u001b[0;m  \u001b[0;38;2;255;184;108mmain.go\u001b[0;m  \u001b[0;38;2;255;184;108mmain_test.go\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[16.821907, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[71C\u001b[K\u001b[0;4;33m_test/'\r\n\r\n\u001b[0;m\u001b[K\u001b[0;38;2;255;184;108mREADME.md\u001b[0;m  \u001b[0;7;38;2;189;147;249m_test/\u001b[0;m  \u001b[0;38;2;189;147;249mcmd/\u001b[0;m  \u001b[0;38;2;255;184;108mmain.go\u001b[0;m  \u001b[0;38;2;255;184;108mmain_test.go\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[16.972401, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[71C\u001b[K\u001b[0;4;33mcmd/'\r\n\r\n\u001b[11C\u001b[0;m\u001b[K\u001b[0;38;2;189;147;249m_test/\u001b[0;m  \u001b[0;7;38;2;189;147;249mcmd/\u001b[0;m  \u001b[0;38;2;255;184;108mmain.go\u001b[0;m  \u001b[0;38;2;255;184;108mmain_test.go\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"]
+[17.128891, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'positional1 --bool=true \"--string\" two cmd/'\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[76C\u001b[?25h"]
+[17.128986, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[76C\u001b[?25h"]
+[17.222747, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'positional1 --bool=true \"--string\" two cmd/_test/'\r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7;38;2;189;147;249m_test/        \u001b[0;m  \u001b[0;38;2;255;184;108mchain.go     \u001b[0;m  \u001b[0;38;2;255;184;108mhelp_test.go        \u001b[0;m  \u001b[0;38;2;255;184;108mmodifier.go       \u001b[0;m  \u001b[0;38;2;255;184;108mroot.go     \r\n\u001b[0;38;2;189;147;249m_test_files/  \u001b[0;m  \u001b[0;38;2;255;184;108mchain_test.go\u001b[0;m  \u001b[0;38;2;255;184;108minjection.go        \u001b[0;m  \u001b[0;38;2;255;184;108mmodifier_test.go  \u001b[0;m  \u001b[0;38;2;255;184;108mroot_test.go\r\naction.go     \u001b[0;m  \u001b[0;38;2;255;184;108mflag.go      \u001b[0;m  \u001b[0;38;2;255;184;108minterspersed.go     \u001b[0;m  \u001b[0;38;2;255;184;108mmultiparts.go     \u001b[0;m  \u001b[0;38;2;255;184;108mspecial.go  \r\naction_test.go\u001b[0;m  \u001b[0;38;2;255;184;108mgroup.go     \u001b[0;m  \u001b[0;38;2;255;184;108minterspersed_test.go\u001b[0;m  \u001b[0;38;2;255;184;108mmultiparts_test.go\u001b[0;m\u001b[4A\r\u001b[22C\u001b[?25h"]
+[17.600369, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[80C\u001b[K\u001b[0;4;33m_files/'\r\n\r\n\u001b[0;m\u001b[K\u001b[0;38;2;189;147;249m_test/        \u001b[0;m  \u001b[0;38;2;255;184;108mchain.go     \u001b[0;m  \u001b[0;38;2;255;184;108mhelp_test.go        \u001b[0;m  \u001b[0;38;2;255;184;108mmodifier.go       \u001b[0;m  \u001b[0;38;2;255;184;108mroot.go     \r\n\u001b[0;m\u001b[K\u001b[0;7;38;2;189;147;249m_test_files/  \u001b[0;m  \u001b[0;38;2;255;184;108mchain_test.go\u001b[0;m  \u001b[0;38;2;255;184;108minjection.go        \u001b[0;m  \u001b[0;38;2;255;184;108mmodifier_test.go  \u001b[0;m  \u001b[0;38;2;255;184;108mroot_test.go\r\n\r\n\u001b[0;m\u001b[4A\r\u001b[22C\u001b[?25h"]
+[17.758825, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[75C\u001b[K\u001b[0;4;33maction.go '\r\n\r\n\r\n\u001b[0;m\u001b[K\u001b[0;38;2;189;147;249m_test_files/  \u001b[0;m  \u001b[0;38;2;255;184;108mchain_test.go\u001b[0;m  \u001b[0;38;2;255;184;108minjection.go        \u001b[0;m  \u001b[0;38;2;255;184;108mmodifier_test.go  \u001b[0;m  \u001b[0;38;2;255;184;108mroot_test.go\r\n\u001b[0;m\u001b[K\u001b[0;7;38;2;255;184;108maction.go     \u001b[0;m  \u001b[0;38;2;255;184;108mflag.go      \u001b[0;m  \u001b[0;38;2;255;184;108minterspersed.go     \u001b[0;m  \u001b[0;38;2;255;184;108mmultiparts.go     \u001b[0;m  \u001b[0;38;2;255;184;108mspecial.go  \r\n\u001b[0;m\u001b[4A\r\u001b[22C\u001b[?25h"]
+[17.915926, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[81C\u001b[K\u001b[0;4;33m_test.go '\r\n\r\n\r\n\r\n\u001b[0;m\u001b[K\u001b[0;38;2;255;184;108maction.go     \u001b[0;m  \u001b[0;38;2;255;184;108mflag.go      \u001b[0;m  \u001b[0;38;2;255;184;108minterspersed.go     \u001b[0;m  \u001b[0;38;2;255;184;108mmultiparts.go     \u001b[0;m  \u001b[0;38;2;255;184;108mspecial.go  \r\n\u001b[0;m\u001b[K\u001b[0;7;38;2;255;184;108maction_test.go\u001b[0;m  \u001b[0;38;2;255;184;108mgroup.go     \u001b[0;m  \u001b[0;38;2;255;184;108minterspersed_test.go\u001b[0;m  \u001b[0;38;2;255;184;108mmultiparts_test.go\u001b[0;m\u001b[4A\r\u001b[22C\u001b[?25h"]
+[18.24392, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'positional1 --bool=true \"--string\" two cmd/action_test.go '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[91C\u001b[?25h"]
+[18.244327, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[91C\u001b[?25h"]
+[20.97018, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\r\u001b[6C\u001b[?25h"]
+[20.970582, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"]
+[20.971644, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"]
+[20.990051, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"]
+[21.474883, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[0;31me\u001b[0;m\r\u001b[7C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"]
+[21.667764, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[7C\u001b[0;31mx\u001b[0;m\r\u001b[8C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[8C\u001b[?25h"]
+[21.813837, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[8C\u001b[0;31mi\u001b[0;m\r\u001b[9C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[9C\u001b[?25h"]
+[21.934165, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\u001b[0;32mexit\u001b[0;m\r\u001b[10C\u001b[?25h"]
+[21.93427, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[10C\u001b[?25h"]
+[22.035087, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\n\r\u001b[?25h\u001b[?7h\u001b[?2004l\r"]
diff --git a/docs/src/carapace/action/split.md b/docs/src/carapace/action/split.md
new file mode 100644
index 0000000..fbfac8a
--- /dev/null
+++ b/docs/src/carapace/action/split.md
@@ -0,0 +1,27 @@
+# Split
+
+[`Split`] splits `Context.Value` using a shell lexer.
+
+```go
+carapace.ActionCallback(func(c carapace.Context) carapace.Action {
+	cmd := &cobra.Command{}
+	carapace.Gen(cmd).Standalone()
+	cmd.Flags().BoolP("bool", "b", false, "bool flag")
+	cmd.Flags().StringP("string", "s", "", "string flag")
+
+	carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
+		"string": carapace.ActionValues("one", "two", "three"),
+	})
+
+	carapace.Gen(cmd).PositionalCompletion(
+		carapace.ActionValues("pos1", "positional1"),
+		carapace.ActionFiles(),
+	)
+
+	return carapace.ActionExecute(cmd)
+}).Split()
+```
+
+![](./split.cast)
+
+[`Split`]: https://pkg.go.dev/github.com/rsteube/carapace#Action.Split
diff --git a/example/cmd/modifier.go b/example/cmd/modifier.go
index 94fe935..f7f69f3 100644
--- a/example/cmd/modifier.go
+++ b/example/cmd/modifier.go
@@ -33,6 +33,7 @@ func init() {
 	modifierCmd.Flags().String("prefix", "", "Prefix()")
 	modifierCmd.Flags().String("retain", "", "Retain()")
 	modifierCmd.Flags().String("shift", "", "Shift()")
+	modifierCmd.Flags().String("split", "", "Split()")
 	modifierCmd.Flags().String("style", "", "Style()")
 	modifierCmd.Flags().String("stylef", "", "StyleF()")
 	modifierCmd.Flags().String("styler", "", "StyleR()")
@@ -123,6 +124,23 @@ func init() {
 		"shift": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
 			return carapace.ActionMessage("%#v", c.Args)
 		}).Shift(1),
+		"split": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
+			cmd := &cobra.Command{}
+			carapace.Gen(cmd).Standalone()
+			cmd.Flags().BoolP("bool", "b", false, "bool flag")
+			cmd.Flags().StringP("string", "s", "", "string flag")
+
+			carapace.Gen(cmd).FlagCompletion(carapace.ActionMap{
+				"string": carapace.ActionValues("one", "two", "three"),
+			})
+
+			carapace.Gen(cmd).PositionalCompletion(
+				carapace.ActionValues("pos1", "positional1"),
+				carapace.ActionFiles(),
+			)
+
+			return carapace.ActionExecute(cmd)
+		}).Split(),
 		"style": carapace.ActionValues(
 			"one",
 			"two",
diff --git a/internal/lexer/lexer.go b/internal/lexer/lexer.go
new file mode 100644
index 0000000..5afac04
--- /dev/null
+++ b/internal/lexer/lexer.go
@@ -0,0 +1,62 @@
+package lexer
+
+import (
+	"strings"
+
+	"github.com/rsteube/carapace/third_party/github.com/google/shlex"
+)
+
+type State int
+
+const (
+	UNQUOTED = iota
+	OPEN_DOUBLE
+	OPEN_SINGLE
+)
+
+type Tokenset struct {
+	Tokens []string
+	Prefix string
+	State  State
+}
+
+func Split(s string) (*Tokenset, error) {
+	tokenset, err := split(s)
+	if err != nil && err.Error() == "EOF found when expecting closing quote" {
+		tokenset, err = split(s + `_"`)
+		if err == nil {
+			last := tokenset.Tokens[len(tokenset.Tokens)-1]
+			tokenset.Tokens[len(tokenset.Tokens)-1] = last[:len(last)-1]
+			tokenset.Prefix = tokenset.Prefix[:len(tokenset.Prefix)-1]
+			tokenset.State = OPEN_DOUBLE
+		}
+	}
+	if err != nil && err.Error() == "EOF found when expecting closing quote" {
+		tokenset, err = split(s + `_'`)
+		if err == nil {
+			last := tokenset.Tokens[len(tokenset.Tokens)-1]
+			tokenset.Tokens[len(tokenset.Tokens)-1] = last[:len(last)-1]
+			tokenset.Prefix = tokenset.Prefix[:len(tokenset.Prefix)-1]
+			tokenset.State = OPEN_SINGLE
+		}
+	}
+	return tokenset, err
+}
+
+func split(s string) (*Tokenset, error) {
+	splitted, err := shlex.Split(s)
+	if strings.HasSuffix(s, " ") {
+		splitted = append(splitted, "")
+	}
+	if err != nil {
+		return nil, err
+	}
+
+	if len(splitted) == 0 {
+		splitted = []string{""}
+	}
+	return &Tokenset{
+		Tokens: splitted,
+		Prefix: s[:strings.LastIndex(s, splitted[len(splitted)-1])],
+	}, nil
+}
diff --git a/third_party/github.com/google/shlex/COPYING b/third_party/github.com/google/shlex/COPYING
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/third_party/github.com/google/shlex/COPYING
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/third_party/github.com/google/shlex/README b/third_party/github.com/google/shlex/README
new file mode 100644
index 0000000..c86bcc0
--- /dev/null
+++ b/third_party/github.com/google/shlex/README
@@ -0,0 +1,2 @@
+go-shlex is a simple lexer for go that supports shell-style quoting,
+commenting, and escaping.
diff --git a/third_party/github.com/google/shlex/shlex.go b/third_party/github.com/google/shlex/shlex.go
new file mode 100644
index 0000000..04d2ded
--- /dev/null
+++ b/third_party/github.com/google/shlex/shlex.go
@@ -0,0 +1,415 @@
+/*
+Copyright 2012 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+Package shlex implements a simple lexer which splits input in to tokens using
+shell-style rules for quoting and commenting.
+
+The basic use case uses the default ASCII lexer to split a string into sub-strings:
+
+	shlex.Split("one \"two three\" four") -> []string{"one", "two three", "four"}
+
+To process a stream of strings:
+
+	l := NewLexer(os.Stdin)
+	for ; token, err := l.Next(); err != nil {
+		// process token
+	}
+
+To access the raw token stream (which includes tokens for comments):
+
+	  t := NewTokenizer(os.Stdin)
+	  for ; token, err := t.Next(); err != nil {
+		// process token
+	  }
+*/
+package shlex
+
+import (
+	"bufio"
+	"fmt"
+	"io"
+	"strings"
+)
+
+// TokenType is a top-level token classification: A word, space, comment, unknown.
+type TokenType int
+
+// runeTokenClass is the type of a UTF-8 character classification: A quote, space, escape.
+type runeTokenClass int
+
+// the internal state used by the lexer state machine
+type lexerState int
+
+// Token is a (type, value) pair representing a lexographical token.
+type Token struct {
+	tokenType TokenType
+	value     string
+}
+
+// Equal reports whether tokens a, and b, are equal.
+// Two tokens are equal if both their types and values are equal. A nil token can
+// never be equal to another token.
+func (a *Token) Equal(b *Token) bool {
+	if a == nil || b == nil {
+		return false
+	}
+	if a.tokenType != b.tokenType {
+		return false
+	}
+	return a.value == b.value
+}
+
+// Named classes of UTF-8 runes
+const (
+	spaceRunes            = " \t\r\n"
+	escapingQuoteRunes    = `"`
+	nonEscapingQuoteRunes = "'"
+	escapeRunes           = `\`
+	commentRunes          = "#"
+)
+
+// Classes of rune token
+const (
+	unknownRuneClass runeTokenClass = iota
+	spaceRuneClass
+	escapingQuoteRuneClass
+	nonEscapingQuoteRuneClass
+	escapeRuneClass
+	commentRuneClass
+	eofRuneClass
+)
+
+// Classes of lexographic token
+const (
+	UnknownToken TokenType = iota
+	WordToken
+	SpaceToken
+	CommentToken
+)
+
+// Lexer state machine states
+const (
+	startState           lexerState = iota // no runes have been seen
+	inWordState                            // processing regular runes in a word
+	escapingState                          // we have just consumed an escape rune; the next rune is literal
+	escapingQuotedState                    // we have just consumed an escape rune within a quoted string
+	quotingEscapingState                   // we are within a quoted string that supports escaping ("...")
+	quotingState                           // we are within a string that does not support escaping ('...')
+	commentState                           // we are within a comment (everything following an unquoted or unescaped #
+)
+
+// tokenClassifier is used for classifying rune characters.
+type tokenClassifier map[rune]runeTokenClass
+
+func (typeMap tokenClassifier) addRuneClass(runes string, tokenType runeTokenClass) {
+	for _, runeChar := range runes {
+		typeMap[runeChar] = tokenType
+	}
+}
+
+// newDefaultClassifier creates a new classifier for ASCII characters.
+func newDefaultClassifier() tokenClassifier {
+	t := tokenClassifier{}
+	t.addRuneClass(spaceRunes, spaceRuneClass)
+	t.addRuneClass(escapingQuoteRunes, escapingQuoteRuneClass)
+	t.addRuneClass(nonEscapingQuoteRunes, nonEscapingQuoteRuneClass)
+	t.addRuneClass(escapeRunes, escapeRuneClass)
+	t.addRuneClass(commentRunes, commentRuneClass)
+	return t
+}
+
+// ClassifyRune classifiees a rune
+func (t tokenClassifier) ClassifyRune(runeVal rune) runeTokenClass {
+	return t[runeVal]
+}
+
+// Lexer turns an input stream into a sequence of tokens. Whitespace and comments are skipped.
+type Lexer Tokenizer
+
+// NewLexer creates a new lexer from an input stream.
+func NewLexer(r io.Reader) *Lexer {
+
+	return (*Lexer)(NewTokenizer(r))
+}
+
+// Next returns the next word, or an error. If there are no more words,
+// the error will be io.EOF.
+func (l *Lexer) Next() (string, error) {
+	for {
+		token, err := (*Tokenizer)(l).Next()
+		if err != nil {
+			return "", err
+		}
+		switch token.tokenType {
+		case WordToken:
+			return token.value, nil
+		case CommentToken:
+			// skip comments
+		default:
+			return "", fmt.Errorf("Unknown token type: %v", token.tokenType)
+		}
+	}
+}
+
+// Tokenizer turns an input stream into a sequence of typed tokens
+type Tokenizer struct {
+	input      bufio.Reader
+	classifier tokenClassifier
+}
+
+// NewTokenizer creates a new tokenizer from an input stream.
+func NewTokenizer(r io.Reader) *Tokenizer {
+	input := bufio.NewReader(r)
+	classifier := newDefaultClassifier()
+	return &Tokenizer{
+		input:      *input,
+		classifier: classifier}
+}
+
+// scanStream scans the stream for the next token using the internal state machine.
+// It will panic if it encounters a rune which it does not know how to handle.
+func (t *Tokenizer) scanStream() (*Token, error) {
+	state := startState
+	var tokenType TokenType
+	var value []rune
+	var nextRune rune
+	var nextRuneType runeTokenClass
+	var err error
+
+	for {
+		nextRune, _, err = t.input.ReadRune()
+		nextRuneType = t.classifier.ClassifyRune(nextRune)
+
+		if err == io.EOF {
+			nextRuneType = eofRuneClass
+			err = nil
+		} else if err != nil {
+			return nil, err
+		}
+
+		switch state {
+		case startState: // no runes read yet
+			{
+				switch nextRuneType {
+				case eofRuneClass:
+					{
+						return nil, io.EOF
+					}
+				case spaceRuneClass:
+					{
+					}
+				case escapingQuoteRuneClass:
+					{
+						tokenType = WordToken
+						state = quotingEscapingState
+					}
+				case nonEscapingQuoteRuneClass:
+					{
+						tokenType = WordToken
+						state = quotingState
+					}
+				case escapeRuneClass:
+					{
+						tokenType = WordToken
+						state = escapingState
+					}
+				case commentRuneClass:
+					{
+						tokenType = CommentToken
+						state = commentState
+					}
+				default:
+					{
+						tokenType = WordToken
+						value = append(value, nextRune)
+						state = inWordState
+					}
+				}
+			}
+		case inWordState: // in a regular word
+			{
+				switch nextRuneType {
+				case eofRuneClass:
+					{
+						token := &Token{
+							tokenType: tokenType,
+							value:     string(value)}
+						return token, err
+					}
+				case spaceRuneClass:
+					{
+						token := &Token{
+							tokenType: tokenType,
+							value:     string(value)}
+						return token, err
+					}
+				case escapingQuoteRuneClass:
+					{
+						state = quotingEscapingState
+					}
+				case nonEscapingQuoteRuneClass:
+					{
+						state = quotingState
+					}
+				case escapeRuneClass:
+					{
+						state = escapingState
+					}
+				default:
+					{
+						value = append(value, nextRune)
+					}
+				}
+			}
+		case escapingState: // the rune after an escape character
+			{
+				switch nextRuneType {
+				case eofRuneClass:
+					{
+						err = fmt.Errorf("EOF found after escape character")
+						token := &Token{
+							tokenType: tokenType,
+							value:     string(value)}
+						return token, err
+					}
+				default:
+					{
+						state = inWordState
+						value = append(value, nextRune)
+					}
+				}
+			}
+		case escapingQuotedState: // the next rune after an escape character, in double quotes
+			{
+				switch nextRuneType {
+				case eofRuneClass:
+					{
+						err = fmt.Errorf("EOF found after escape character")
+						token := &Token{
+							tokenType: tokenType,
+							value:     string(value)}
+						return token, err
+					}
+				default:
+					{
+						state = quotingEscapingState
+						value = append(value, nextRune)
+					}
+				}
+			}
+		case quotingEscapingState: // in escaping double quotes
+			{
+				switch nextRuneType {
+				case eofRuneClass:
+					{
+						err = fmt.Errorf("EOF found when expecting closing quote")
+						token := &Token{
+							tokenType: tokenType,
+							value:     string(value)}
+						return token, err
+					}
+				case escapingQuoteRuneClass:
+					{
+						state = inWordState
+					}
+				case escapeRuneClass:
+					{
+						state = escapingQuotedState
+					}
+				default:
+					{
+						value = append(value, nextRune)
+					}
+				}
+			}
+		case quotingState: // in non-escaping single quotes
+			{
+				switch nextRuneType {
+				case eofRuneClass:
+					{
+						err = fmt.Errorf("EOF found when expecting closing quote")
+						token := &Token{
+							tokenType: tokenType,
+							value:     string(value)}
+						return token, err
+					}
+				case nonEscapingQuoteRuneClass:
+					{
+						state = inWordState
+					}
+				default:
+					{
+						value = append(value, nextRune)
+					}
+				}
+			}
+		case commentState: // in a comment
+			{
+				switch nextRuneType {
+				case eofRuneClass:
+					{
+						token := &Token{
+							tokenType: tokenType,
+							value:     string(value)}
+						return token, err
+					}
+				case spaceRuneClass:
+					{
+						if nextRune == '\n' {
+							state = startState
+							token := &Token{
+								tokenType: tokenType,
+								value:     string(value)}
+							return token, err
+						} else {
+							value = append(value, nextRune)
+						}
+					}
+				default:
+					{
+						value = append(value, nextRune)
+					}
+				}
+			}
+		default:
+			{
+				return nil, fmt.Errorf("Unexpected state: %v", state)
+			}
+		}
+	}
+}
+
+// Next returns the next token in the stream.
+func (t *Tokenizer) Next() (*Token, error) {
+	return t.scanStream()
+}
+
+// Split partitions a string into a slice of strings.
+func Split(s string) ([]string, error) {
+	l := NewLexer(strings.NewReader(s))
+	subStrings := make([]string, 0)
+	for {
+		word, err := l.Next()
+		if err != nil {
+			if err == io.EOF {
+				return subStrings, nil
+			}
+			return subStrings, err
+		}
+		subStrings = append(subStrings, word)
+	}
+}


Test patch:
diff --git a/example/cmd/modifier_test.go b/example/cmd/modifier_test.go
index c3dfbd5..12c2fa3 100644
--- a/example/cmd/modifier_test.go
+++ b/example/cmd/modifier_test.go
@@ -158,3 +158,84 @@ func TestPrefix(t *testing.T) {
 				Tag("files"))
 	})
 }
+
+func TestSplit(t *testing.T) {
+	os.Unsetenv("LS_COLORS")
+	sandbox.Package(t, "github.com/rsteube/carapace/example")(func(s *sandbox.Sandbox) {
+		s.Files("subdir/file1.txt", "")
+
+		s.Run("modifier", "--split", "").
+			Expect(carapace.ActionValues(
+				"pos1",
+				"positional1",
+			).NoSpace('*').
+				Suffix(" ").
+				Usage("Split()"))
+
+		s.Run("modifier", "--split", "pos1 ").
+			Expect(carapace.ActionValues(
+				"subdir/",
+			).StyleF(style.ForPathExt).
+				Prefix("pos1 ").
+				NoSpace('*').
+				Usage("Split()").
+				Tag("files"))
+
+		s.Run("modifier", "--split", "pos1 \"").
+			Expect(carapace.ActionValues(
+				"subdir/",
+			).StyleF(style.ForPathExt).
+				Prefix("pos1 ").
+				Suffix("\"").
+				NoSpace('*').
+				Usage("Split()").
+				Tag("files"))
+
+		s.Run("modifier", "--split", "pos1 '").
+			Expect(carapace.ActionValues(
+				"subdir/",
+			).StyleF(style.ForPathExt).
+				Prefix("pos1 ").
+				Suffix("'").
+				NoSpace('*').
+				Usage("Split()").
+				Tag("files"))
+
+		s.Run("modifier", "--split", "pos1 --").
+			Expect(carapace.ActionStyledValuesDescribed(
+				"--bool", "bool flag", style.Default,
+				"--string", "string flag", style.Blue,
+			).Prefix("pos1 ").
+				Suffix(" ").
+				NoSpace('*').
+				Usage("Split()").
+				Tag("flags"))
+
+		s.Run("modifier", "--split", "pos1 --bool=").
+			Expect(carapace.ActionStyledValues(
+				"true", style.Green,
+				"false", style.Red,
+			).Prefix("pos1 --bool=").
+				Suffix(" ").
+				NoSpace('*').
+				Usage("bool flag"))
+
+		s.Run("modifier", "--split", "pos1 \"--bool=").
+			Expect(carapace.ActionStyledValues(
+				"true", style.Green,
+				"false", style.Red,
+			).Prefix("pos1 \"--bool=").
+				Suffix("\" ").
+				NoSpace('*').
+				Usage("bool flag"))
+
+		s.Run("modifier", "--split", "pos1 '--bool=").
+			Expect(carapace.ActionStyledValues(
+				"true", style.Green,
+				"false", style.Red,
+			).Prefix("pos1 '--bool=").
+				Suffix("' ").
+				NoSpace('*').
+				Usage("bool flag"))
+	})
+}
diff --git a/internal/lexer/lexer_test.go b/internal/lexer/lexer_test.go
new file mode 100644
index 0000000..212dea0
--- /dev/null
+++ b/internal/lexer/lexer_test.go
@@ -0,0 +1,99 @@
+package lexer
+
+import (
+	"encoding/json"
+	"testing"
+
+	"github.com/rsteube/carapace/internal/assert"
+)
+
+func TestSplit(t *testing.T) {
+	_test := func(s string, expected Tokenset) {
+		t.Run(s, func(t *testing.T) {
+			tokenset, err := Split(s)
+			if err != nil {
+				t.Error(err.Error())
+			}
+
+			expected, _ := json.MarshalIndent(expected, "", "  ")
+			actual, _ := json.MarshalIndent(tokenset, "", "  ")
+			assert.Equal(t, string(expected), string(actual))
+		})
+	}
+
+	_test(``, Tokenset{
+		Tokens: []string{""},
+	})
+
+	_test(` `, Tokenset{
+		Tokens: []string{""},
+		Prefix: ` `,
+	})
+
+	_test(`"example`, Tokenset{
+		Tokens: []string{"example"},
+		State:  OPEN_DOUBLE,
+	})
+
+	_test(`'example`, Tokenset{
+		Tokens: []string{"example"},
+		State:  OPEN_SINGLE,
+	})
+
+	_test(`example a`, Tokenset{
+		Tokens: []string{"example", "a"},
+		Prefix: `example `,
+	})
+
+	_test(`example  a`, Tokenset{
+		Tokens: []string{"example", "a"},
+		Prefix: `example  `,
+	})
+
+	_test(`example "a`, Tokenset{
+		Tokens: []string{"example", "a"},
+		Prefix: `example `,
+		State:  OPEN_DOUBLE,
+	})
+
+	_test(`example  'a`, Tokenset{
+		Tokens: []string{"example", "a"},
+		Prefix: `example  `,
+		State:  OPEN_SINGLE,
+	})
+
+	_test(`example action `, Tokenset{
+		Tokens: []string{"example", "action", ""},
+		Prefix: `example action `,
+	})
+
+	_test(`example action -`, Tokenset{
+		Tokens: []string{"example", "action", "-"},
+		Prefix: `example action `,
+	})
+
+	_test(`example action --`, Tokenset{
+		Tokens: []string{"example", "action", "--"},
+		Prefix: `example action `,
+	})
+
+	_test(`example action - `, Tokenset{
+		Tokens: []string{"example", "action", "-", ""},
+		Prefix: `example action - `,
+	})
+
+	_test(`example action -- `, Tokenset{
+		Tokens: []string{"example", "action", "--", ""},
+		Prefix: `example action -- `,
+	})
+
+	_test(`example "action" -- `, Tokenset{
+		Tokens: []string{"example", "action", "--", ""},
+		Prefix: `example "action" -- `,
+	})
+
+	_test(`example 'action' -- `, Tokenset{
+		Tokens: []string{"example", "action", "--", ""},
+		Prefix: `example 'action' -- `,
+	})
+}
diff --git a/third_party/github.com/google/shlex/shlex_test.go b/third_party/github.com/google/shlex/shlex_test.go
new file mode 100644
index 0000000..51268ce
--- /dev/null
+++ b/third_party/github.com/google/shlex/shlex_test.go
@@ -0,0 +1,101 @@
+/*
+Copyright 2012 Google Inc. All Rights Reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package shlex
+
+import (
+	"strings"
+	"testing"
+)
+
+var (
+	// one two "three four" "five \"six\"" seven#eight # nine # ten
+	// eleven 'twelve\'
+	testString = "one two \"three four\" \"five \\\"six\\\"\" seven#eight # nine # ten\n eleven 'twelve\\' thirteen=13 fourteen/14"
+)
+
+func TestClassifier(t *testing.T) {
+	classifier := newDefaultClassifier()
+	tests := map[rune]runeTokenClass{
+		' ':  spaceRuneClass,
+		'"':  escapingQuoteRuneClass,
+		'\'': nonEscapingQuoteRuneClass,
+		'#':  commentRuneClass}
+	for runeChar, want := range tests {
+		got := classifier.ClassifyRune(runeChar)
+		if got != want {
+			t.Errorf("ClassifyRune(%v) -> %v. Want: %v", runeChar, got, want)
+		}
+	}
+}
+
+func TestTokenizer(t *testing.T) {
+	testInput := strings.NewReader(testString)
+	expectedTokens := []*Token{
+		{WordToken, "one"},
+		{WordToken, "two"},
+		{WordToken, "three four"},
+		{WordToken, "five \"six\""},
+		{WordToken, "seven#eight"},
+		{CommentToken, " nine # ten"},
+		{WordToken, "eleven"},
+		{WordToken, "twelve\\"},
+		{WordToken, "thirteen=13"},
+		{WordToken, "fourteen/14"}}
+
+	tokenizer := NewTokenizer(testInput)
+	for i, want := range expectedTokens {
+		got, err := tokenizer.Next()
+		if err != nil {
+			t.Error(err)
+		}
+		if !got.Equal(want) {
+			t.Errorf("Tokenizer.Next()[%v] of %q -> %v. Want: %v", i, testString, got, want)
+		}
+	}
+}
+
+func TestLexer(t *testing.T) {
+	testInput := strings.NewReader(testString)
+	expectedStrings := []string{"one", "two", "three four", "five \"six\"", "seven#eight", "eleven", "twelve\\", "thirteen=13", "fourteen/14"}
+
+	lexer := NewLexer(testInput)
+	for i, want := range expectedStrings {
+		got, err := lexer.Next()
+		if err != nil {
+			t.Error(err)
+		}
+		if got != want {
+			t.Errorf("Lexer.Next()[%v] of %q -> %v. Want: %v", i, testString, got, want)
+		}
+	}
+}
+
+func TestSplit(t *testing.T) {
+	want := []string{"one", "two", "three four", "five \"six\"", "seven#eight", "eleven", "twelve\\", "thirteen=13", "fourteen/14"}
+	got, err := Split(testString)
+	if err != nil {
+		t.Error(err)
+	}
+	if len(want) != len(got) {
+		t.Errorf("Split(%q) -> %v. Want: %v", testString, got, want)
+	}
+	for i := range got {
+		if got[i] != want[i] {
+			t.Errorf("Split(%q)[%v] -> %v. Want: %v", testString, i, got[i], want[i])
+		}
+	}
+}