-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,097 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
{"version": 2, "width": 108, "height": 24, "timestamp": 1690392077, "env": {"SHELL": "elvish", "TERM": "tmux-256color"}} | ||
[0.078465, "o", "\u001b[?7h\u001b[7m⏎\u001b[m \r \r\u001b[?7l\u001b[?2004h"] | ||
[0.079091, "o", "\u001b[?25l\r???> ???> \r\u001b[5C\u001b[?25h\u001b[?25l\r\u001b[5C\u001b[K\r\u001b[5C\u001b[?25h"] | ||
[0.091788, "o", "\u001b[?25l\r\r\u001b[5C\u001b[?25h\u001b[?25l\r\r\u001b[5C\u001b[?25h"] | ||
[0.091933, "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.766098, "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"] | ||
[0.766287, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[7C\u001b[?25h"] | ||
[0.784573, "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.952355, "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"] | ||
[1.115515, "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\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[9C\u001b[?25h"] | ||
[1.230336, "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"] | ||
[1.230421, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[10C\u001b[?25h"] | ||
[1.31764, "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"] | ||
[1.396956, "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"] | ||
[1.497506, "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\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[13C\u001b[?25h"] | ||
[1.556128, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[13C \r\u001b[14C\u001b[?25h"] | ||
[1.556218, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[14C\u001b[?25h"] | ||
[1.734389, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[14Cm\r\u001b[15C\u001b[?25h"] | ||
[1.734499, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[15C\u001b[?25h"] | ||
[1.805083, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[15Co\r\u001b[16C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[16C\u001b[?25h"] | ||
[1.955922, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[16Cdifier \r\u001b[23C\u001b[?25h"] | ||
[2.2755, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[23C-\r\u001b[24C\u001b[?25h"] | ||
[2.435598, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[24C-\r\u001b[25C\u001b[?25h"] | ||
[2.435702, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[25C\u001b[?25h"] | ||
[2.507351, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[25Cs\r\u001b[26C\u001b[?25h"] | ||
[2.507573, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[26C\u001b[?25h"] | ||
[2.656398, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[26Cp\r\u001b[27C\u001b[?25h"] | ||
[2.656504, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[27C\u001b[?25h"] | ||
[2.914668, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[27Clit \r\u001b[31C\u001b[?25h"] | ||
[3.591351, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[0;33m'pos\u001b[0;m\r\u001b[35C\u001b[?25h"] | ||
[4.000959, "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.629769, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'pos1 '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[38C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[38C\u001b[?25h"] | ||
[4.841815, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[38C-\r\u001b[39C\u001b[?25h\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[39C\u001b[?25h"] | ||
[5.013282, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'pos1 --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"] | ||
[6.298726, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[39C\u001b[K\u001b[0;4;33mstring '\r\n\r\n\u001b[0;m\u001b[K--bool\u001b[0;2m (bool flag)\u001b[0;m \u001b[0;7;34m--string\u001b[0;2;7m (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.242436, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'pos1 --string '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[47C\u001b[?25h"] | ||
[7.242548, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[47C\u001b[?25h"] | ||
[7.37394, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'pos1 --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"] | ||
[7.864491, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[46C\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"] | ||
[8.021653, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[47C\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"] | ||
[8.292493, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'pos1 --string two '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[51C\u001b[?25h"] | ||
[8.293454, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[51C\u001b[?25h"] | ||
[8.294475, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[51C\u001b[?25h"] | ||
[8.294789, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[51C\u001b[?25h"] | ||
[8.295564, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[51C\u001b[?25h"] | ||
[8.29635, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[51C\u001b[?25h"] | ||
[8.296527, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[51C\u001b[?25h"] | ||
[8.296633, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[51C\u001b[?25h"] | ||
[8.972497, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[51C-\r\u001b[52C\u001b[?25h"] | ||
[9.14571, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[52C-\r\u001b[53C\u001b[?25h"] | ||
[9.145817, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[53C\u001b[?25h"] | ||
[9.295241, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'pos1 --string two --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[1A\r\u001b[22C\u001b[?25h"] | ||
[9.875059, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'pos1 --string two --bool '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[58C\u001b[?25h"] | ||
[9.875183, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[58C\u001b[?25h"] | ||
[10.056459, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[57C\u001b[K\r\u001b[57C\u001b[?25h"] | ||
[10.236407, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[56C\u001b[K\r\u001b[56C\u001b[?25h"] | ||
[10.307922, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[56C\u001b[0;33m=\u001b[0;m\r\u001b[57C\u001b[?25h"] | ||
[10.307993, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[57C\u001b[?25h"] | ||
[10.429317, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'pos1 --string two --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"] | ||
[11.242227, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[57C\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.819496, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'pos1 --string two --bool=true '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[63C\u001b[?25h"] | ||
[11.819604, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[63C\u001b[?25h"] | ||
[13.270469, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[63C\u001b[0;33m\"\u001b[0;m\r\u001b[64C\u001b[?25h"] | ||
[13.270956, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[64C\u001b[?25h"] | ||
[13.586174, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[63C\u001b[K\r\u001b[63C\u001b[?25h"] | ||
[13.586272, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[63C\u001b[?25h"] | ||
[13.692969, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[62C\u001b[K\r\u001b[62C\u001b[?25h"] | ||
[13.894107, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[62C\u001b[0;33m\"\u001b[0;m\r\u001b[63C\u001b[?25h"] | ||
[13.894197, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[63C\u001b[?25h"] | ||
[14.083592, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[63C\u001b[0;33mpos\u001b[0;m\r\u001b[66C\u001b[?25h"] | ||
[14.595357, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;4;33m'pos1 --string two --bool=true \"pos2\" '\r\n\u001b[0;1;37;45m COMPLETING argument \u001b[0;m \r\n\u001b[0;7mpos2\u001b[0;m positional2\u001b[1A\r\u001b[22C\u001b[?25h"] | ||
[15.655501, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[66C\u001b[K\u001b[0;4;33mitional2\" '\r\n\r\n\u001b[0;m\u001b[Kpos2 \u001b[0;7mpositional2\u001b[0;m\u001b[1A\r\u001b[22C\u001b[?25h"] | ||
[16.240866, "o", "\u001b[?25l\u001b[3A\r\r\n\r\n\u001b[31C\u001b[K\u001b[0;33m'pos1 --string two --bool=true \"positional2\" '\u001b[0;m\r\n\u001b[J\u001b[A\r\u001b[77C\u001b[?25h"] | ||
[16.240978, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[77C\u001b[?25h"] | ||
[19.377509, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[K\r\u001b[6C\u001b[?25h"] | ||
[19.37868, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"] | ||
[19.396225, "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\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"] | ||
[19.39648, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"] | ||
[19.396618, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[6C\u001b[?25h"] | ||
[19.621854, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\u001b[6C\u001b[0;31me\u001b[0;m\r\u001b[7C\u001b[?25h"] | ||
[19.84434, "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"] | ||
[19.948184, "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"] | ||
[20.109817, "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"] | ||
[20.109903, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\u001b[10C\u001b[?25h"] | ||
[20.23343, "o", "\u001b[?25l\u001b[2A\r\r\n\r\n\r\n\r\u001b[?25h"] | ||
[20.233512, "o", "\u001b[?7h\u001b[?2004l\r"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.ActionValues("pos2", "positional2"), | ||
) | ||
|
||
return carapace.ActionExecute(cmd) | ||
}).Split() | ||
``` | ||
|
||
![](./split.cast) | ||
|
||
[`Split`]: https://pkg.go.dev/github.com/rsteube/carapace#Action.Split |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Oops, something went wrong.