diff --git a/cmd/install/install.go b/cmd/install/install.go index dfa1963..831d971 100644 --- a/cmd/install/install.go +++ b/cmd/install/install.go @@ -65,7 +65,7 @@ func installers() (i []installer) { break } } - if f := rcFile(".zshrc"); f != "" { + if f := zshrcPath(); f != "" { i = append(i, zsh{f}) } if d := fishConfigDir(); d != "" { @@ -74,6 +74,19 @@ func installers() (i []installer) { return } +// zshrcPath returns the path to the first .zshrc found following the +// same order of preference as zsh. (zsh will only look in HOME if ZDOTDIR is undefined) +func zshrcPath() string { + if zDotDir := os.Getenv("ZDOTDIR"); zDotDir != "" { + fp := filepath.Join(zDotDir, ".zshrc") + // Return early if fp exists and is not a directory + if info, err := os.Stat(fp); err == nil && !info.IsDir() { + return fp + } + } + return rcFile(".zshrc") +} + func fishConfigDir() string { configDir := filepath.Join(getConfigHomePath(), "fish") if configDir == "" {