Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jan 16, 2024
1 parent 8e38fb5 commit cbbb0d5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/actions/bridge/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bridge
import (
_ "embed"
"fmt"
"os"
"strings"

"github.com/rsteube/carapace"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cbbb0d5

Please sign in to comment.