Skip to content

Commit

Permalink
zsh: source .zshrc for custom fpath directories
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Dec 6, 2024
1 parent 4ad49d2 commit 76479b3
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/bridges/zsh.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package bridges

import (
"fmt"
"os"
"runtime"
"sort"
"strings"

"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace/pkg/execlog"
"github.com/carapace-sh/carapace/pkg/xdg"
)

func Zsh() []string {
Expand All @@ -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")
Expand Down

0 comments on commit 76479b3

Please sign in to comment.