From cbbb0d549837435b5c5b3076a61d3dd6f2d467cd Mon Sep 17 00:00:00 2001 From: rsteube Date: Tue, 16 Jan 2024 16:17:18 +0100 Subject: [PATCH] tmp --- pkg/actions/bridge/bash.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pkg/actions/bridge/bash.go b/pkg/actions/bridge/bash.go index d7279b8..256a298 100644 --- a/pkg/actions/bridge/bash.go +++ b/pkg/actions/bridge/bash.go @@ -3,6 +3,7 @@ package bridge import ( _ "embed" "fmt" + "os" "strings" "github.com/rsteube/carapace" @@ -35,8 +36,21 @@ func ActionBash(command ...string) carapace.Action { return carapace.ActionMessage(err.Error()) } - c.Setenv("COMP_LINE", shlex.Join(args)) - return carapace.ActionExecCommand("bash", "--rcfile", configPath, "-i", "-c", bashSnippet)(func(output []byte) carapace.Action { + joined := shlex.Join(args) + if c.Value == "" { + joined = strings.TrimSuffix(joined, `""`) + } + c.Setenv("COMP_LINE", joined) + + file, err := os.CreateTemp(os.TempDir(), "carapace-bridge_bash_*") + if err != nil { + return carapace.ActionMessage(err.Error()) + } + defer os.Remove(file.Name()) + + os.WriteFile(file.Name(), []byte(bashSnippet), os.ModePerm) + + return carapace.ActionExecCommand("bash", "--rcfile", configPath, "-i", file.Name())(func(output []byte) carapace.Action { lines := strings.Split(string(output), "\n") return carapace.ActionValues(lines[:len(lines)-1]...).StyleF(style.ForPath) }).Invoke(c).ToA().NoSpace([]rune("/=@:.,")...) // TODO check compopt for nospace