Skip to content

Clean up Go-related configuration and add .zshenv for environment setup #13

@iammohitsakhuja

Description

@iammohitsakhuja

Problem

The current Go-related configuration in our dotfiles is scattered across multiple files, making it harder to maintain and understand. Additionally, we're missing a .zshenv file for proper environment variable setup.

Current Issues:

  1. Scattered Go configuration: Go environment setup is split between:

    • macos/config/.exports (lines 5-7): GOENV_ROOT and PATH setup
    • macos/config/.zshrc (lines 93-98): goenv init and additional GOROOT/GOPATH setup
  2. Missing .zshenv file: We don't have a .zshenv file, which is the proper place for environment variables that should be available to all shell sessions (interactive and non-interactive).

  3. Incomplete Rust/Cargo setup: While we have rust-analyzer installed via Homebrew, we're missing proper Cargo environment sourcing.

Proposed Solution

1. Create .zshenv file

Create macos/config/.zshenv to handle environment variables that should be available globally:

  • Move GOENV_ROOT and goenv PATH setup from .exports
  • Add Cargo environment sourcing (source "$HOME/.cargo/env")
  • Include other essential environment variables that should be available to all shells

2. Clean up existing files

  • .exports: Remove Go-specific environment variables (lines 5-7)
  • .zshrc: Keep only the goenv init execution, remove redundant PATH exports
  • install.sh: Add .zshenv to the list of files to be symlinked/copied

3. Improve Go packages script

  • Update macos/scripts/go-packages.sh to use latest Go version
  • Add commonly used Go packages to install by default

Benefits

  1. Better organization: Environment variables in .zshenv, initialization hooks in .zshrc
  2. Proper shell hierarchy: .zshenv is sourced for all zsh invocations, .zshrc only for interactive shells
  3. Rust/Cargo support: Proper Cargo environment setup for Rust development
  4. Maintainability: Clearer separation of concerns

Implementation Checklist

  • Create macos/config/.zshenv with:
    • GOENV_ROOT and goenv PATH setup (moved from .exports)
    • Cargo environment sourcing
    • Other essential environment variables
  • Update macos/config/.exports:
    • Remove Go-related environment variables (lines 5-7)
  • Update macos/config/.zshrc:
    • Clean up goenv setup (remove redundant PATH exports)
    • Keep only goenv init execution
  • Update macos/install.sh:
    • Add .zshenv to files list for symlinking/copying
  • Update macos/scripts/go-packages.sh:
    • Update to latest Go version
    • Consider adding default Go packages

Files to be Modified

  • macos/config/.zshenv (new file)
  • macos/config/.exports
  • macos/config/.zshrc
  • macos/install.sh
  • macos/scripts/go-packages.sh

Additional Context

This cleanup aligns with shell best practices where:

  • .zshenv contains environment variables for all shells
  • .zshrc contains interactive shell configuration
  • Version managers (like goenv) are initialized in interactive shells but their PATH setup happens at the environment level

The same .zshenv approach can be extended for other language environments like Python (pyenv), Node (nodenv), etc.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions