diff --git a/pkg/bridges/zsh.go b/pkg/bridges/zsh.go index 202529c..281f929 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,13 @@ 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 path, err := zshrc(); err == nil { + script = fmt.Sprintf("source %v;%v", path, 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") @@ -49,3 +56,15 @@ func Zsh() []string { return completers, nil }) } + +func zshrc() (string, error) { + configDir, err := xdg.UserConfigDir() + if err != nil { + return "", err + } + path := configDir + "/carapace/bridge/zsh/.zshrc" + if _, err := os.Stat(path); err != nil { + return "", err + } + return path, nil +}