Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions home-manager/programs/fish/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
enable = true;
shellInit = ''
# Local binaries should be available before login/interactive-only PATH setup.
set -gx PATH $HOME/.bun/install/global/node_modules/.bin $HOME/.bun/bin $HOME/.cargo/bin $HOME/.local/bin $PATH
# ~/.bun/bin (real native bun) must precede the global node_modules/.bin so a
# transitively hoisted `bun`/`bunx` npm stub can never shadow the real binary.
set -gx PATH $HOME/.bun/bin $HOME/.bun/install/global/node_modules/.bin $HOME/.cargo/bin $HOME/.local/bin $PATH

# Set XDG_RUNTIME_DIR on Linux for consistent socket paths (e.g., zellij)
if test (uname) = "Linux"
Expand Down Expand Up @@ -52,10 +54,12 @@
fish_add_path -p -m ~/.local/bin
fish_add_path -p -m ~/.cargo/bin
fish_add_path -p -m ~/.local/scripts
fish_add_path -p -m ~/.bun/bin
fish_add_path -p -m /opt/homebrew/opt/postgresql@18/bin
fish_add_path -p -m /opt/homebrew/bin
fish_add_path -p -m ~/.bun/install/global/node_modules/.bin
# ~/.bun/bin last => frontmost, so the real native bun/bunx always win over
# any hoisted `bun` npm stub living in the global node_modules/.bin above.
fish_add_path -p -m ~/.bun/bin
Comment on lines +60 to +62

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The entire block of fish_add_path commands (lines 50-62) is duplicated identically in both loginShellInit and interactiveShellInit (lines 75-87).

To adhere to the DRY (Don't Repeat Yourself) principle and prevent future maintenance issues (such as paths drifting out of sync when added, removed, or reordered), consider extracting this common path setup block into a Nix let binding at the top of the file.

Suggested Refactoring

At the top of home-manager/programs/fish/default.nix:

let
  commonPaths = ''
    # Last line = highest priority (-p -m prepends+moves; last call ends up at front of fish_user_paths)
    fish_add_path -p -m /nix/var/nix/profiles/default/bin
    fish_add_path -p -m ~/.nix-profile/bin
    fish_add_path -p -m /etc/profiles/per-user/${config.home.username}/bin
    fish_add_path -p -m ~/go/bin
    fish_add_path -p -m ~/.local/bin
    fish_add_path -p -m ~/.cargo/bin
    fish_add_path -p -m ~/.local/scripts
    fish_add_path -p -m /opt/homebrew/opt/postgresql@18/bin
    fish_add_path -p -m /opt/homebrew/bin
    fish_add_path -p -m ~/.bun/install/global/node_modules/.bin
    # ~/.bun/bin last => frontmost, so the real native bun/bunx always win over
    # any hoisted `bun` npm stub living in the global node_modules/.bin above.
    fish_add_path -p -m ~/.bun/bin
  '';
in
{
  # ...
}

Then, reference it in both shell initialization blocks:

    loginShellInit = ''
      if test -f /opt/homebrew/bin/brew
          eval "$(/opt/homebrew/bin/brew shellenv)"
      end

      ${commonPaths}
    '';
    interactiveShellInit = ''
      source ${config.home.homeDirectory}/.config/fish/functions/_hm_load_env_file.fish
      _hm_load_env_file
      set fish_greeting
      set fish_theme dracula

      if test -f /opt/homebrew/bin/brew
          eval "$(/opt/homebrew/bin/brew shellenv)"
      end

      ${commonPaths}
      # Worktrunk shell init
      if type -q wt
        wt config shell init fish | source
      end
      # ...
    '';

'';
interactiveShellInit = ''
source ${config.home.homeDirectory}/.config/fish/functions/_hm_load_env_file.fish
Expand All @@ -75,10 +79,12 @@
fish_add_path -p -m ~/.local/bin
fish_add_path -p -m ~/.cargo/bin
fish_add_path -p -m ~/.local/scripts
fish_add_path -p -m ~/.bun/bin
fish_add_path -p -m /opt/homebrew/opt/postgresql@18/bin
fish_add_path -p -m /opt/homebrew/bin
fish_add_path -p -m ~/.bun/install/global/node_modules/.bin
# ~/.bun/bin last => frontmost, so the real native bun/bunx always win over
# any hoisted `bun` npm stub living in the global node_modules/.bin above.
fish_add_path -p -m ~/.bun/bin
# Worktrunk shell init
if type -q wt
wt config shell init fish | source
Expand Down
Loading