From 76479b36f68120fe4dbee4ae64af0ef1b553cd55 Mon Sep 17 00:00:00 2001 From: rsteube Date: Fri, 6 Dec 2024 20:35:06 +0100 Subject: [PATCH] zsh: source .zshrc for custom `fpath` directories --- pkg/bridges/zsh.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/bridges/zsh.go b/pkg/bridges/zsh.go index 202529c..42c638d 100644 --- a/pkg/bridges/zsh.go +++ b/pkg/bridges/zsh.go @@ -1,6 +1,7 @@ package bridges import ( + "fmt" "os" "runtime" "sort" @@ -8,6 +9,7 @@ import ( "github.com/carapace-sh/carapace" "github.com/carapace-sh/carapace/pkg/execlog" + "github.com/carapace-sh/carapace/pkg/xdg" ) func Zsh() []string { @@ -20,8 +22,16 @@ func Zsh() []string { } return cache("zsh", func() ([]string, error) { - out, err := execlog.Command("zsh", "--no-rcs", "-c", "printf '%s\n' $fpath").Output() - if err != nil { + script := "printf '%s\n' $fpath" + if configDir, err := xdg.UserConfigDir(); err == nil { + zshrc := configDir + "/carapace/bridge/zsh/.zshrc" + if _, err := os.Stat(zshrc); err == nil { + script = fmt.Sprintf("source %v;%v", zshrc, script) + } + } + + out, err := execlog.Command("zsh", "--no-rcs", "-c", script).Output() + if err != nil { // TODO log stderr return nil, err } lines := strings.Split(string(out), "\n")