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 77b1c86
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 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,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")
Expand Down Expand Up @@ -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
}

0 comments on commit 77b1c86

Please sign in to comment.