zsh: add plugins submodule

This commit is contained in:
Robin Stumm 2017-09-04 16:39:14 +02:00
parent cda222d2ec
commit f98f72a825
No known key found for this signature in database
GPG key ID: 3DA3D7B8285FBE55

View file

@ -37,6 +37,27 @@ let
}; };
}; };
pluginModule = types.submodule ({ config, ... }: {
options = {
src = mkOption {
type = types.path;
description = "Path to the plugin folder. Will be added to <envar>fpath</envar> and <envar>PATH</envar>.";
};
name = mkOption {
type = types.str;
description = "The name of the plugin. Use <option>file</option> instead if the script name does not follow convention.";
};
file = mkOption {
type = types.str;
description = "The plugin script to source.";
};
};
config.file = mkDefault "${config.name}.plugin.zsh";
});
in in
{ {
@ -74,7 +95,36 @@ in
initExtra = mkOption { initExtra = mkOption {
default = ""; default = "";
type = types.lines; type = types.lines;
description = "Extra commands that should be added to .zshrc."; description = "Extra commands that should be added to <filename>.zshrc</filename>.";
};
plugins = mkOption {
type = types.listOf pluginModule;
default = [];
example = literalExample ''
[
{
# will source zsh-autosuggestions.plugin.zsh
name = "zsh-autosuggestions";
src = pkgs.fetchFromGitHub {
owner = "zsh-users";
repo = "zsh-autosuggestions";
rev = "v0.4.0";
sha256 = "0z6i9wjjklb4lvr7zjhbphibsyx51psv50gm07mbb0kj9058j6kc";
};
}
{
file = "init.sh";
src = pkgs.fetchFromGitHub {
owner = "b4b4r07";
repo = "enhancd";
rev = "v2.2.1";
sha256 = "0iqa9j09fwm6nj5rpip87x3hnvbbz9w9ajgm6wkrd5fls8fn8i5g";
};
}
]
'';
description = "Plugins to source in <filename>.zshrc</filename>.";
}; };
}; };
}; };
@ -109,15 +159,28 @@ in
HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help" HELPDIR="${pkgs.zsh}/share/zsh/$ZSH_VERSION/help"
${if cfg.enableCompletion then "autoload -U compinit && compinit" else ""} ${concatStrings (map (plugin: ''
path+="${plugin.src}"
fpath+="${plugin.src}"
'') cfg.plugins)}
${optionalString cfg.enableCompletion "autoload -U compinit && compinit -C"}
${optionalString (cfg.enableAutosuggestions) ${optionalString (cfg.enableAutosuggestions)
"source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh" "source ${pkgs.zsh-autosuggestions}/share/zsh-autosuggestions/zsh-autosuggestions.zsh"
} }
${concatStrings (map (plugin: ''
source "${plugin.src}/${plugin.file}"
'') cfg.plugins)}
${aliasesStr} ${aliasesStr}
${cfg.initExtra} ${cfg.initExtra}
''; '';
programs.zsh = mkIf (builtins.length cfg.plugins > 0) {
enableCompletion = mkDefault true;
};
} }
); );
} }