Hi all,
I am in the process of migrating to home-manager for my home. One of the things I currently do is source all files in ~/.sh.d
. I have found how to copy all files from my git repo to that location:
home.file = {
".sh.d" = {
source = ./sh.d;
recursive = true;
};
};
My question is, how do I tell zsh
and bash
to source everything inside that directory?
I was able to use variables for sharing common snippets across both bash and zsh:
{ pkgs, ... }:
let
myAliases = {
ll = "ls -l";
fastfetch = "/usr/libexec/ublue-fastfetch";
};
sourceShD = "
source ~/.sh.d/*
";
in
{
home.file = {
".sh.d" = {
source = ./sh.d;
recursive = true;
};
};
programs.bash = {
shellAliases = myAliases;
enable = true;
enableCompletion = true;
bashrcExtra = sourceShD;
};
programs.zsh = {
shellAliases = myAliases;
enable = true;
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
initExtra = sourceShD;
};
}
I suppose there may be better alternatives, but at least I am able to share the same declaration across both shells with this approach.
2 Likes
I don’t think there are really better alternatives. That is a really good approach.
But you may encounter some problems in the future. For example when you want to use starship. Starship needs an .rc entry that is specific for each shell. You would then encounter conflicts between them. But if you just declare basic stuff and don’t use something that needs shell specific declaration, that would be the best approach in my opinion for your problem.
1 Like