fix: ZDOTDIR and XDG_CONFIG_HOME config detecting (#51)
From this discussion: https://www.reddit.com/r/zsh/comments/1v8rq7s/comment/p09b05o/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button --- Problem: Iris hardcodes config paths to `~/.zshrc` and `~/.config/fish/config.fish`. This ignores users' custom `ZDOTDIR` or `XDG_CONFIG_HOME` setups, polluting their `$HOME` directory during init and failing to scan their actual aliases. Also, ZDOTDIR is often set in `~/.zshenv` without export, making it invisible to Go's `os.Getenv` Solution: - Bash: default `$HOME/.bashrc` so dont mind about it - For Zsh, Iris now probes zsh directly (`zsh -c "echo $ZDOTDIR"`) with a timeout to accurately resolve custom paths even if they aint exported - For Fish, Iris now natively respects the `XDG_CONFIG_HOME` environment variable - Shared this robust resolution logic across init, uninstall, and alias scanning - Fixed alias scanning to process files in the correct zsh startup order (`.zshenv` -> `.zprofile` -> `.zshrc`) and correctly merge them
This commit is contained in:
+3
-2
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/versenilvis/iris/integration/shell"
|
||||
"github.com/versenilvis/iris/internal/config"
|
||||
)
|
||||
|
||||
@@ -135,13 +136,13 @@ var setupCmd = &cobra.Command{
|
||||
|
||||
switch shellName {
|
||||
case "zsh":
|
||||
configFile = filepath.Join(home, ".zshrc")
|
||||
configFile = filepath.Join(shell.GetZshConfigDir(), ".zshrc")
|
||||
evalCmd = `eval "$(iris init zsh)"`
|
||||
case "bash":
|
||||
configFile = filepath.Join(home, ".bashrc")
|
||||
evalCmd = `eval "$(iris init bash)"`
|
||||
case "fish":
|
||||
configFile = filepath.Join(home, ".config", "fish", "config.fish")
|
||||
configFile = filepath.Join(shell.GetFishConfigDir(), "config.fish")
|
||||
evalCmd = `iris init fish | source`
|
||||
default:
|
||||
fmt.Printf("Unsupported shell: %s. Please add iris init manually.\n", shellName)
|
||||
|
||||
Reference in New Issue
Block a user