From a296d5e2d087b1f1281257109aa5610cd4e26c06 Mon Sep 17 00:00:00 2001 From: rsteube Date: Sun, 19 Jan 2025 15:46:18 +0100 Subject: [PATCH] zsh: fix fully quoted value --- docs/src/SUMMARY.md | 2 + .../vhs/doubleQuote/out/doubleQuote.zsh.ascii | 4 +- .../src/development/vhs/doubleQuotePartial.md | 18 +++++ .../doubleQuotePartial.bash.tape | 8 ++ .../doubleQuotePartial.elvish.tape | 8 ++ .../doubleQuotePartial.fish.tape | 8 ++ .../doubleQuotePartial.nushell.tape | 8 ++ .../doubleQuotePartial.oil.tape | 8 ++ .../doubleQuotePartial.powershell.tape | 8 ++ .../doubleQuotePartial.xonsh.tape | 8 ++ .../doubleQuotePartial.zsh.tape | 8 ++ .../out/doubleQuoteOpen.bash.ascii | 40 ++++++++++ .../out/doubleQuoteOpen.elvish.ascii | 40 ++++++++++ .../out/doubleQuoteOpen.fish.ascii | 40 ++++++++++ .../out/doubleQuoteOpen.nushell.ascii | 40 ++++++++++ .../out/doubleQuoteOpen.oil.ascii | 40 ++++++++++ .../out/doubleQuoteOpen.powershell.ascii | 40 ++++++++++ .../out/doubleQuoteOpen.xonsh.ascii | 40 ++++++++++ .../out/doubleQuoteOpen.zsh.ascii | 40 ++++++++++ .../out/doubleQuotePartial.bash.ascii | 40 ++++++++++ .../out/doubleQuotePartial.elvish.ascii | 40 ++++++++++ .../out/doubleQuotePartial.fish.ascii | 40 ++++++++++ .../out/doubleQuotePartial.nushell.ascii | 40 ++++++++++ .../out/doubleQuotePartial.oil.ascii | 40 ++++++++++ .../out/doubleQuotePartial.powershell.ascii | 40 ++++++++++ .../out/doubleQuotePartial.xonsh.ascii | 40 ++++++++++ .../out/doubleQuotePartial.zsh.ascii | 40 ++++++++++ .../vhs/singleQuote/out/singleQuote.zsh.ascii | 4 +- .../src/development/vhs/singleQuotePartial.md | 18 +++++ .../out/singleQuotePartial.bash.ascii | 40 ++++++++++ .../out/singleQuotePartial.elvish.ascii | 40 ++++++++++ .../out/singleQuotePartial.fish.ascii | 40 ++++++++++ .../out/singleQuotePartial.nushell.ascii | 40 ++++++++++ .../out/singleQuotePartial.oil.ascii | 40 ++++++++++ .../out/singleQuotePartial.powershell.ascii | 40 ++++++++++ .../out/singleQuotePartial.xonsh.ascii | 40 ++++++++++ .../out/singleQuotePartial.zsh.ascii | 40 ++++++++++ .../singleQuotePartial.bash.tape | 8 ++ .../singleQuotePartial.elvish.tape | 8 ++ .../singleQuotePartial.fish.tape | 8 ++ .../singleQuotePartial.nushell.tape | 8 ++ .../singleQuotePartial.oil.tape | 8 ++ .../singleQuotePartial.powershell.tape | 8 ++ .../singleQuotePartial.xonsh.tape | 8 ++ .../singleQuotePartial.zsh.tape | 8 ++ .../development/vhs/word/out/word.xonsh.ascii | 4 +- example/cmd/_test/zsh.sh | 8 +- internal/env/env.go | 14 +--- internal/shell/zsh/action.go | 74 ++++++++++++++----- internal/shell/zsh/snippet.go | 8 +- 50 files changed, 1198 insertions(+), 44 deletions(-) create mode 100644 docs/src/development/vhs/doubleQuotePartial.md create mode 100644 docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.bash.tape create mode 100644 docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.elvish.tape create mode 100644 docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.fish.tape create mode 100644 docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.nushell.tape create mode 100644 docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.oil.tape create mode 100644 docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.powershell.tape create mode 100644 docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.xonsh.tape create mode 100644 docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.zsh.tape create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.bash.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.elvish.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.fish.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.nushell.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.oil.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.powershell.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.xonsh.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.zsh.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.bash.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.elvish.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.fish.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.nushell.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.oil.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.powershell.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.xonsh.ascii create mode 100644 docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.zsh.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial.md create mode 100644 docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.bash.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.elvish.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.fish.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.nushell.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.oil.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.powershell.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.xonsh.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.zsh.ascii create mode 100644 docs/src/development/vhs/singleQuotePartial/singleQuotePartial.bash.tape create mode 100644 docs/src/development/vhs/singleQuotePartial/singleQuotePartial.elvish.tape create mode 100644 docs/src/development/vhs/singleQuotePartial/singleQuotePartial.fish.tape create mode 100644 docs/src/development/vhs/singleQuotePartial/singleQuotePartial.nushell.tape create mode 100644 docs/src/development/vhs/singleQuotePartial/singleQuotePartial.oil.tape create mode 100644 docs/src/development/vhs/singleQuotePartial/singleQuotePartial.powershell.tape create mode 100644 docs/src/development/vhs/singleQuotePartial/singleQuotePartial.xonsh.tape create mode 100644 docs/src/development/vhs/singleQuotePartial/singleQuotePartial.zsh.tape diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 431dba67f..521111e64 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -122,7 +122,9 @@ - [Nospace](./development/vhs/nospace.md) - [Double Quote](./development/vhs/doubleQuote.md) - [Double Quote Open](./development/vhs/doubleQuoteOpen.md) + - [Double Quote Partial](./development/vhs/doubleQuotePartial.md) - [Single Quote](./development/vhs/singleQuote.md) - [Single Quote Open](./development/vhs/singleQuoteOpen.md) + - [Single Quote Partial](./development/vhs/singleQuotePartial.md) - [Escape](./development/vhs/escape.md) - [Redirect](./development/vhs/redirect.md) diff --git a/docs/src/development/vhs/doubleQuote/out/doubleQuote.zsh.ascii b/docs/src/development/vhs/doubleQuote/out/doubleQuote.zsh.ascii index 806b13fc7..5f0d448ac 100644 --- a/docs/src/development/vhs/doubleQuote/out/doubleQuote.zsh.ascii +++ b/docs/src/development/vhs/doubleQuote/out/doubleQuote.zsh.ascii @@ -22,7 +22,7 @@ ──────────────────────────────────────────────────────────────────────────────── -> example "action " +> example "action" @@ -30,7 +30,7 @@ ──────────────────────────────────────────────────────────────────────────────── -> example "action " +> example "action" diff --git a/docs/src/development/vhs/doubleQuotePartial.md b/docs/src/development/vhs/doubleQuotePartial.md new file mode 100644 index 000000000..f333f648f --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial.md @@ -0,0 +1,18 @@ +# Double Quote Partial + +- bash +![](./doubleQuotePartial/out/doubleQuotePartial.bash.gif) +- elvish +![](./doubleQuotePartial/out/doubleQuotePartial.elvish.gif) +- fish +![](./doubleQuotePartial/out/doubleQuotePartial.fish.gif) +- nushell +![](./doubleQuotePartial/out/doubleQuotePartial.nushell.gif) +- oil +![](./doubleQuotePartial/out/doubleQuotePartial.oil.gif) +- powershell +![](./doubleQuotePartial/out/doubleQuotePartial.powershell.gif) +- xonsh +![](./doubleQuotePartial/out/doubleQuotePartial.xonsh.gif) +- zsh +![](./doubleQuotePartial/out/doubleQuotePartial.zsh.gif) diff --git a/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.bash.tape b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.bash.tape new file mode 100644 index 000000000..6dd1ff94e --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.bash.tape @@ -0,0 +1,8 @@ +Source ../bash.tape + +Output out/doubleQuotePartial.bash.gif +Output out/doubleQuotePartial.bash.ascii + +Type `example action embeddedP1 "embeddedP2 w"i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.elvish.tape b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.elvish.tape new file mode 100644 index 000000000..90a589176 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.elvish.tape @@ -0,0 +1,8 @@ +Source ../elvish.tape + +Output out/doubleQuotePartial.elvish.gif +Output out/doubleQuotePartial.elvish.ascii + +Type `example action embeddedP1 "embeddedP2 w"i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.fish.tape b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.fish.tape new file mode 100644 index 000000000..3f4726838 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.fish.tape @@ -0,0 +1,8 @@ +Source ../fish.tape + +Output out/doubleQuotePartial.fish.gif +Output out/doubleQuotePartial.fish.ascii + +Type `example action embeddedP1 "embeddedP2 w"i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.nushell.tape b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.nushell.tape new file mode 100644 index 000000000..aed6bdce7 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.nushell.tape @@ -0,0 +1,8 @@ +Source ../nushell.tape + +Output out/doubleQuotePartial.nushell.gif +Output out/doubleQuotePartial.nushell.ascii + +Type `example action embeddedP1 "embeddedP2 w"i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.oil.tape b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.oil.tape new file mode 100644 index 000000000..505571a78 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.oil.tape @@ -0,0 +1,8 @@ +Source ../oil.tape + +Output out/doubleQuotePartial.oil.gif +Output out/doubleQuotePartial.oil.ascii + +Type `example action embeddedP1 "embeddedP2 w"i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.powershell.tape b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.powershell.tape new file mode 100644 index 000000000..70de7e6ed --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.powershell.tape @@ -0,0 +1,8 @@ +Source ../powershell.tape + +Output out/doubleQuotePartial.powershell.gif +Output out/doubleQuotePartial.powershell.ascii + +Type `example action embeddedP1 "embeddedP2 w"i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.xonsh.tape b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.xonsh.tape new file mode 100644 index 000000000..388311140 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.xonsh.tape @@ -0,0 +1,8 @@ +Source ../xonsh.tape + +Output out/doubleQuotePartial.xonsh.gif +Output out/doubleQuotePartial.xonsh.ascii + +Type `example action embeddedP1 "embeddedP2 w"i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.zsh.tape b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.zsh.tape new file mode 100644 index 000000000..01b287182 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/doubleQuotePartial.zsh.tape @@ -0,0 +1,8 @@ +Source ../zsh.tape + +Output out/doubleQuotePartial.zsh.gif +Output out/doubleQuotePartial.zsh.ascii + +Type `example action embeddedP1 "embeddedP2 w"i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.bash.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.bash.ascii new file mode 100644 index 000000000..b8a98a778 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.bash.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.elvish.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.elvish.ascii new file mode 100644 index 000000000..b8a98a778 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.elvish.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.fish.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.fish.ascii new file mode 100644 index 000000000..b8a98a778 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.fish.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.nushell.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.nushell.ascii new file mode 100644 index 000000000..eaaabe469 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.nushell.ascii @@ -0,0 +1,40 @@ +> > + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.oil.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.oil.ascii new file mode 100644 index 000000000..7f440412c --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.oil.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.powershell.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.powershell.ascii new file mode 100644 index 000000000..7f440412c --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.powershell.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.xonsh.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.xonsh.ascii new file mode 100644 index 000000000..eee64aac8 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.xonsh.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + embeddedP2 with space + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + embeddedP2 with space + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.zsh.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.zsh.ascii new file mode 100644 index 000000000..c8c37893f --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuoteOpen.zsh.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2\ with\ space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2\ with\ space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.bash.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.bash.ascii new file mode 100644 index 000000000..7c6654cd8 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.bash.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.elvish.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.elvish.ascii new file mode 100644 index 000000000..5e09dc8cc --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.elvish.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + COMPLETING argument +embeddedP2 with space + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + COMPLETING argument +embeddedP2 with space + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.fish.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.fish.ascii new file mode 100644 index 000000000..f84640d98 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.fish.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"ith\ space + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"ith\ space + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.nushell.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.nushell.ascii new file mode 100644 index 000000000..a2bde60ce --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.nushell.ascii @@ -0,0 +1,40 @@ +> > + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.oil.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.oil.ascii new file mode 100644 index 000000000..bdb4a6185 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.oil.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 embeddedP2 with space + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 embeddedP2 with space + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.powershell.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.powershell.ascii new file mode 100644 index 000000000..5f3753bc7 --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.powershell.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.xonsh.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.xonsh.ascii new file mode 100644 index 000000000..ab2c04fef --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.xonsh.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + embeddedP2 with space + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + embeddedP2 with space + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.zsh.ascii b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.zsh.ascii new file mode 100644 index 000000000..b9f4d8c4e --- /dev/null +++ b/docs/src/development/vhs/doubleQuotePartial/out/doubleQuotePartial.zsh.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 w"i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2\ with\ space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2\ with\ space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuote/out/singleQuote.zsh.ascii b/docs/src/development/vhs/singleQuote/out/singleQuote.zsh.ascii index 7ca905a41..24710d2bc 100644 --- a/docs/src/development/vhs/singleQuote/out/singleQuote.zsh.ascii +++ b/docs/src/development/vhs/singleQuote/out/singleQuote.zsh.ascii @@ -22,7 +22,7 @@ ──────────────────────────────────────────────────────────────────────────────── -> example 'action ' +> example 'action' @@ -30,7 +30,7 @@ ──────────────────────────────────────────────────────────────────────────────── -> example 'action ' +> example 'action' diff --git a/docs/src/development/vhs/singleQuotePartial.md b/docs/src/development/vhs/singleQuotePartial.md new file mode 100644 index 000000000..a1169864a --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial.md @@ -0,0 +1,18 @@ +# Single Quote Partial + +- bash +![](./singleQuotePartial/out/singleQuotePartial.bash.gif) +- elvish +![](./singleQuotePartial/out/singleQuotePartial.elvish.gif) +- fish +![](./singleQuotePartial/out/singleQuotePartial.fish.gif) +- nushell +![](./singleQuotePartial/out/singleQuotePartial.nushell.gif) +- oil +![](./singleQuotePartial/out/singleQuotePartial.oil.gif) +- powershell +![](./singleQuotePartial/out/singleQuotePartial.powershell.gif) +- xonsh +![](./singleQuotePartial/out/singleQuotePartial.xonsh.gif) +- zsh +![](./singleQuotePartial/out/singleQuotePartial.zsh.gif) diff --git a/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.bash.ascii b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.bash.ascii new file mode 100644 index 000000000..fc39f91e9 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.bash.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.elvish.ascii b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.elvish.ascii new file mode 100644 index 000000000..ac2284e89 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.elvish.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + COMPLETING argument +embeddedP2 with space + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + COMPLETING argument +embeddedP2 with space + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.fish.ascii b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.fish.ascii new file mode 100644 index 000000000..096ce1dbb --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.fish.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'ith\ space + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'ith\ space + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.nushell.ascii b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.nushell.ascii new file mode 100644 index 000000000..f500bfb60 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.nushell.ascii @@ -0,0 +1,40 @@ +> > + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> > example action embeddedP1 "embeddedP2 with space" + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.oil.ascii b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.oil.ascii new file mode 100644 index 000000000..25b374509 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.oil.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 embeddedP2 with space + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 embeddedP2 with space + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.powershell.ascii b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.powershell.ascii new file mode 100644 index 000000000..39e1c54b1 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.powershell.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.xonsh.ascii b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.xonsh.ascii new file mode 100644 index 000000000..a48a7e0e1 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.xonsh.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + embeddedP2 with space + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 with space' + embeddedP2 with space + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.zsh.ascii b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.zsh.ascii new file mode 100644 index 000000000..5e1facfdb --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/out/singleQuotePartial.zsh.ascii @@ -0,0 +1,40 @@ +> + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2 w'i + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2\ with\ space' + + + + + + +──────────────────────────────────────────────────────────────────────────────── +> example action embeddedP1 'embeddedP2\ with\ space' + + + + + + +──────────────────────────────────────────────────────────────────────────────── diff --git a/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.bash.tape b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.bash.tape new file mode 100644 index 000000000..ef787898b --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.bash.tape @@ -0,0 +1,8 @@ +Source ../bash.tape + +Output out/singleQuotePartial.bash.gif +Output out/singleQuotePartial.bash.ascii + +Type `example action embeddedP1 'embeddedP2 w'i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.elvish.tape b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.elvish.tape new file mode 100644 index 000000000..aeaf6aa5d --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.elvish.tape @@ -0,0 +1,8 @@ +Source ../elvish.tape + +Output out/singleQuotePartial.elvish.gif +Output out/singleQuotePartial.elvish.ascii + +Type `example action embeddedP1 'embeddedP2 w'i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.fish.tape b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.fish.tape new file mode 100644 index 000000000..87f0d114f --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.fish.tape @@ -0,0 +1,8 @@ +Source ../fish.tape + +Output out/singleQuotePartial.fish.gif +Output out/singleQuotePartial.fish.ascii + +Type `example action embeddedP1 'embeddedP2 w'i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.nushell.tape b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.nushell.tape new file mode 100644 index 000000000..5e908a361 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.nushell.tape @@ -0,0 +1,8 @@ +Source ../nushell.tape + +Output out/singleQuotePartial.nushell.gif +Output out/singleQuotePartial.nushell.ascii + +Type `example action embeddedP1 'embeddedP2 w'i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.oil.tape b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.oil.tape new file mode 100644 index 000000000..75eef3f27 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.oil.tape @@ -0,0 +1,8 @@ +Source ../oil.tape + +Output out/singleQuotePartial.oil.gif +Output out/singleQuotePartial.oil.ascii + +Type `example action embeddedP1 'embeddedP2 w'i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.powershell.tape b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.powershell.tape new file mode 100644 index 000000000..838503110 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.powershell.tape @@ -0,0 +1,8 @@ +Source ../powershell.tape + +Output out/singleQuotePartial.powershell.gif +Output out/singleQuotePartial.powershell.ascii + +Type `example action embeddedP1 'embeddedP2 w'i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.xonsh.tape b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.xonsh.tape new file mode 100644 index 000000000..fb5940cc4 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.xonsh.tape @@ -0,0 +1,8 @@ +Source ../xonsh.tape + +Output out/singleQuotePartial.xonsh.gif +Output out/singleQuotePartial.xonsh.ascii + +Type `example action embeddedP1 'embeddedP2 w'i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.zsh.tape b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.zsh.tape new file mode 100644 index 000000000..9ef971599 --- /dev/null +++ b/docs/src/development/vhs/singleQuotePartial/singleQuotePartial.zsh.tape @@ -0,0 +1,8 @@ +Source ../zsh.tape + +Output out/singleQuotePartial.zsh.gif +Output out/singleQuotePartial.zsh.ascii + +Type `example action embeddedP1 'embeddedP2 w'i` Sleep 1 Tab@1 + +Sleep 2 diff --git a/docs/src/development/vhs/word/out/word.xonsh.ascii b/docs/src/development/vhs/word/out/word.xonsh.ascii index 00982b242..9043ef6b6 100644 --- a/docs/src/development/vhs/word/out/word.xonsh.ascii +++ b/docs/src/development/vhs/word/out/word.xonsh.ascii @@ -6,7 +6,7 @@ ──────────────────────────────────────────────────────────────────────────────── -> example +> example >/dev/null @@ -14,7 +14,7 @@ ──────────────────────────────────────────────────────────────────────────────── -> example +> example >/dev/null diff --git a/example/cmd/_test/zsh.sh b/example/cmd/_test/zsh.sh index 51d18578c..d95f9346d 100644 --- a/example/cmd/_test/zsh.sh +++ b/example/cmd/_test/zsh.sh @@ -2,14 +2,14 @@ function _example_completion { local words=${words[@]:0:$CURRENT} local IFS=$'\n' - + # shellcheck disable=SC2086,SC2154,SC2155 if echo ${words}"''" | xargs echo 2>/dev/null > /dev/null; then - local lines="$(echo ${words}"''" | CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs example _carapace zsh )" + local lines="$(echo ${words}"''" | CARAPACE_COMPLINE="${words}" CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs example _carapace zsh )" elif echo ${words} | sed "s/\$/'/" | xargs echo 2>/dev/null > /dev/null; then - local lines="$(echo ${words} | sed "s/\$/'/" | CARAPACE_STATE=QUOTING_STATE CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs example _carapace zsh)" + local lines="$(echo ${words} | sed "s/\$/'/" | CARAPACE_COMPLINE="${words}" CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs example _carapace zsh)" else - local lines="$(echo ${words} | sed 's/$/"/' | CARAPACE_STATE=QUOTING_ESCAPING_STATE CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs example _carapace zsh)" + local lines="$(echo ${words} | sed 's/$/"/' | CARAPACE_COMPLINE="${words}" CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs example _carapace zsh)" fi local zstyle message data diff --git a/internal/env/env.go b/internal/env/env.go index 5534535a3..bda4410fd 100644 --- a/internal/env/env.go +++ b/internal/env/env.go @@ -6,11 +6,11 @@ import ( "os" "strings" - shlex "github.com/carapace-sh/carapace-shlex" "github.com/carapace-sh/carapace/internal/common" ) const ( + CARAPACE_COMPLINE = "CARAPACE_COMPLINE" // TODO CARAPACE_COVERDIR = "CARAPACE_COVERDIR" // coverage directory for sandbox tests CARAPACE_EXPERIMENTAL = "CARAPACE_EXPERIMENTAL" // enable experimental features CARAPACE_HIDDEN = "CARAPACE_HIDDEN" // show hidden commands/flags @@ -19,7 +19,6 @@ const ( CARAPACE_MATCH = "CARAPACE_MATCH" // match case insensitive CARAPACE_NOSPACE = "CARAPACE_NOSPACE" // nospace suffixes CARAPACE_SANDBOX = "CARAPACE_SANDBOX" // mock context for sandbox tests - CARAPACE_STATE = "CARAPACE_STATE" // current word state CARAPACE_TOOLTIP = "CARAPACE_TOOLTIP" // enable tooltip style CARAPACE_ZSH_HASH_DIRS = "CARAPACE_ZSH_HASH_DIRS" // zsh hash directories CLICOLOR = "CLICOLOR" // disable color @@ -78,15 +77,8 @@ func Tooltip() bool { return getBool(CARAPACE_TOOLTIP) } -func State() shlex.LexerState { - switch os.Getenv(CARAPACE_STATE) { - case "QUOTING_STATE": - return shlex.QUOTING_STATE - case "QUOTING_ESCAPING_STATE": - return shlex.QUOTING_ESCAPING_STATE - default: - return shlex.START_STATE - } +func Compline() string { + return os.Getenv(CARAPACE_COMPLINE) } func getBool(s string) bool { diff --git a/internal/shell/zsh/action.go b/internal/shell/zsh/action.go index 4ce3d6898..2ceac60b4 100644 --- a/internal/shell/zsh/action.go +++ b/internal/shell/zsh/action.go @@ -2,6 +2,7 @@ package zsh import ( "fmt" + "regexp" "strings" shlex "github.com/carapace-sh/carapace-shlex" @@ -47,8 +48,42 @@ func quoteValue(s string) string { return quoter.Replace(s) } +type state int + +const ( + DEFAULT_STATE state = iota + // Word starts with `"`. + // Values need to end with `"` as well. + // Weirdly regardless whether there are additional quotes within the word. + QUOTING_ESCAPING_STATE + // Word starts with `'`. + // Values need to end with `'` as well. + // Weirdly regardless whether there are additional quotes within the word. + QUOTING_STATE + // Word starts and ends with quotes. + // Space suffix somehow ends up within the quotes. + // `"action"` + // `"action "` + // Workaround for now is to force nospace. + FULLY_QUOTED_STATE +) + // ActionRawValues formats values for zsh func ActionRawValues(currentWord string, meta common.Meta, values common.RawValues) string { + splitted, err := shlex.Split(env.Compline()) + state := DEFAULT_STATE + if err == nil { + rawValue := splitted.CurrentToken().RawValue + switch { + case regexp.MustCompile(`^'$|^'.*[^']$`).MatchString(rawValue): + state = QUOTING_STATE + case regexp.MustCompile(`^"$|^".*[^"]$`).MatchString(rawValue): + state = QUOTING_ESCAPING_STATE + case regexp.MustCompile(`^".*"$|^'.*'$`).MatchString(rawValue): + state = FULLY_QUOTED_STATE + } + } + for index, value := range values { switch value.Tag { case "shorthand flags", "longhand flags": @@ -61,34 +96,35 @@ func ActionRawValues(currentWord string, meta common.Meta, values common.RawValu vals := make([]string, len(values)) displays := make([]string, len(values)) for index, val := range values { - val.Value = sanitizer.Replace(val.Value) - val.Value = quoteValue(val.Value) - val.Value = strings.ReplaceAll(val.Value, `\`, `\\`) // TODO find out why `_describe` needs another backslash - val.Value = strings.ReplaceAll(val.Value, `:`, `\:`) // TODO find out why `_describe` needs another backslash + value := sanitizer.Replace(val.Value) + value = quoteValue(value) + value = strings.ReplaceAll(value, `\`, `\\`) // TODO find out why `_describe` needs another backslash + value = strings.ReplaceAll(value, `:`, `\:`) // TODO find out why `_describe` needs another backslash - switch env.State() { + switch state { // TODO depending on state value needs to be formatted differently // TODO backspace strings are currently an issue - case shlex.QUOTING_STATE: - val.Value = val.Value + `'` - case shlex.QUOTING_ESCAPING_STATE: - val.Value = val.Value + `"` + case QUOTING_STATE: + value = value + `'` + case QUOTING_ESCAPING_STATE: + value = value + `"` } - if !meta.Nospace.Matches(val.Value) { - val.Value = val.Value + " " + if !meta.Nospace.Matches(val.Value) && state != FULLY_QUOTED_STATE { + value += " " } - val.Display = sanitizer.Replace(val.Display) - val.Display = strings.ReplaceAll(val.Display, `\`, `\\`) // TODO find out why `_describe` needs another backslash - val.Display = strings.ReplaceAll(val.Display, `:`, `\:`) // TODO find out why `_describe` needs another backslash - val.Description = sanitizer.Replace(val.Description) - vals[index] = val.Value + display := sanitizer.Replace(val.Display) + display = strings.ReplaceAll(display, `\`, `\\`) // TODO find out why `_describe` needs another backslash + display = strings.ReplaceAll(display, `:`, `\:`) // TODO find out why `_describe` needs another backslash + description := sanitizer.Replace(val.Description) + + vals[index] = value - if strings.TrimSpace(val.Description) == "" { - displays[index] = val.Display + if strings.TrimSpace(description) == "" { + displays[index] = display } else { - displays[index] = fmt.Sprintf("%v:%v", val.Display, val.Description) + displays[index] = fmt.Sprintf("%v:%v", display, description) } } tagGroup = append(tagGroup, strings.Join([]string{tag, strings.Join(displays, "\n"), strings.Join(vals, "\n")}, "\003")) diff --git a/internal/shell/zsh/snippet.go b/internal/shell/zsh/snippet.go index a116df03e..7295151ee 100644 --- a/internal/shell/zsh/snippet.go +++ b/internal/shell/zsh/snippet.go @@ -14,14 +14,14 @@ func Snippet(cmd *cobra.Command) string { function _%v_completion { local words=${words[@]:0:$CURRENT} local IFS=$'\n' - + # shellcheck disable=SC2086,SC2154,SC2155 if echo ${words}"''" | xargs echo 2>/dev/null > /dev/null; then - local lines="$(echo ${words}"''" | CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs %v _carapace zsh )" + local lines="$(echo ${words}"''" | CARAPACE_COMPLINE="${words}" CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs %v _carapace zsh )" elif echo ${words} | sed "s/\$/'/" | xargs echo 2>/dev/null > /dev/null; then - local lines="$(echo ${words} | sed "s/\$/'/" | CARAPACE_STATE=QUOTING_STATE CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs %v _carapace zsh)" + local lines="$(echo ${words} | sed "s/\$/'/" | CARAPACE_COMPLINE="${words}" CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs %v _carapace zsh)" else - local lines="$(echo ${words} | sed 's/$/"/' | CARAPACE_STATE=QUOTING_ESCAPING_STATE CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs %v _carapace zsh)" + local lines="$(echo ${words} | sed 's/$/"/' | CARAPACE_COMPLINE="${words}" CARAPACE_ZSH_HASH_DIRS="$(hash -d)" xargs %v _carapace zsh)" fi local zstyle message data