From ebb3b9ae245734b3ad86978f38f0f2b2b541d617 Mon Sep 17 00:00:00 2001 From: Robin Eikaas Date: Thu, 18 Oct 2018 14:17:03 +0200 Subject: [PATCH 1/2] Look for .zshrc in ZDOTDIR if its defined --- cmd/install/install.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/install/install.go b/cmd/install/install.go index dfa1963..86ee476 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,16 @@ func installers() (i []installer) { return } +func zshrcPath() string { + if zDotDir := os.Getenv("ZDOTDIR"); zDotDir != "" { + f := filepath.Join(zDotDir, ".zshrc") + if info, err := os.Stat(f); err != nil || !info.IsDir() { + return f + } + } + return rcFile(".zshrc") +} + func fishConfigDir() string { configDir := filepath.Join(getConfigHomePath(), "fish") if configDir == "" { From da48f50b5bcb0db3eb8bb3364784c531c6740697 Mon Sep 17 00:00:00 2001 From: Robin Eikaas Date: Fri, 19 Oct 2018 14:21:28 +0200 Subject: [PATCH 2/2] Fixes logic and adds documentation --- cmd/install/install.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/install/install.go b/cmd/install/install.go index 86ee476..831d971 100644 --- a/cmd/install/install.go +++ b/cmd/install/install.go @@ -74,11 +74,14 @@ 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 != "" { - f := filepath.Join(zDotDir, ".zshrc") - if info, err := os.Stat(f); err != nil || !info.IsDir() { - return f + 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")