mirror of
https://github.com/nix-community/home-manager
synced 2024-11-23 03:29:45 +01:00
zsh: add plugins.*.completions paths to fpath
Autocompletion scripts and additional plugin functions are located in specific directories that might not match the plugin source script but need to be included in fpath before calling compinit. An option to provide a path to these scripts is added to add the paths to fpath before calling completionInit.
This commit is contained in:
parent
c2cd2a52e0
commit
e29d786f53
3 changed files with 49 additions and 14 deletions
|
@ -148,19 +148,27 @@ let
|
|||
type = types.str;
|
||||
description = ''
|
||||
The name of the plugin.
|
||||
|
||||
Don't forget to add {option}`file`
|
||||
if the script name does not follow convention.
|
||||
'';
|
||||
};
|
||||
|
||||
file = mkOption {
|
||||
type = types.str;
|
||||
description = "The plugin script to source.";
|
||||
description = ''
|
||||
The plugin script to source.
|
||||
|
||||
Required if the script name does not match {file}`name.plugin.zsh`
|
||||
using the plugin {option}`name` from the plugin {option}`src`.
|
||||
'';
|
||||
};
|
||||
|
||||
completions = mkOption {
|
||||
type = types.listOf types.str;
|
||||
description = "Paths of additional functions to add to {env}`fpath`.";
|
||||
};
|
||||
};
|
||||
|
||||
config.file = mkDefault "${config.name}.plugin.zsh";
|
||||
config.completions = mkDefault [];
|
||||
});
|
||||
|
||||
ohMyZshModule = types.submodule {
|
||||
|
@ -498,16 +506,6 @@ in
|
|||
default = [];
|
||||
example = literalExpression ''
|
||||
[
|
||||
{
|
||||
# will source zsh-autosuggestions.plugin.zsh
|
||||
name = "zsh-autosuggestions";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "zsh-users";
|
||||
repo = "zsh-autosuggestions";
|
||||
rev = "v0.4.0";
|
||||
sha256 = "0z6i9wjjklb4lvr7zjhbphibsyx51psv50gm07mbb0kj9058j6kc";
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "enhancd";
|
||||
file = "init.sh";
|
||||
|
@ -518,6 +516,12 @@ in
|
|||
sha256 = "0iqa9j09fwm6nj5rpip87x3hnvbbz9w9ajgm6wkrd5fls8fn8i5g";
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "wd";
|
||||
src = pkgs.zsh-wd;
|
||||
file = "share/wd/wd.plugin.zsh";
|
||||
completions = [ "share/zsh/site-functions" ];
|
||||
}
|
||||
]
|
||||
'';
|
||||
description = "Plugins to source in {file}`.zshrc`.";
|
||||
|
@ -629,6 +633,9 @@ in
|
|||
(concatStrings (map (plugin: ''
|
||||
path+="$HOME/${pluginsDir}/${plugin.name}"
|
||||
fpath+="$HOME/${pluginsDir}/${plugin.name}"
|
||||
${(optionalString (plugin.completions != []) ''
|
||||
fpath+=(${concatMapStringsSep " " (completion: "\"$HOME/${pluginsDir}/${plugin.name}/${completion}\"") plugin.completions})
|
||||
'')}
|
||||
'') cfg.plugins))
|
||||
|
||||
''
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
zsh-history-path-old-custom = ./history-path-old-custom.nix;
|
||||
zsh-history-ignore-pattern = ./history-ignore-pattern.nix;
|
||||
zsh-history-substring-search = ./history-substring-search.nix;
|
||||
zsh-plugins = ./plugins.nix;
|
||||
zsh-prezto = ./prezto.nix;
|
||||
zsh-syntax-highlighting = ./syntax-highlighting.nix;
|
||||
zsh-abbr = ./zsh-abbr.nix;
|
||||
|
|
27
tests/modules/programs/zsh/plugins.nix
Normal file
27
tests/modules/programs/zsh/plugins.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let mockZshPluginSrc = pkgs.writeText "mockZshPluginSrc" "echo example";
|
||||
in {
|
||||
config = {
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
plugins = [{
|
||||
name = "mockPlugin";
|
||||
file = "share/mockPlugin/mockPlugin.plugin.zsh";
|
||||
src = mockZshPluginSrc;
|
||||
completions =
|
||||
[ "share/zsh/site-functions" "share/zsh/vendor-completions" ];
|
||||
}];
|
||||
};
|
||||
|
||||
test.stubs.zsh = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileRegex home-files/.zshrc '^path+="$HOME/.zsh/plugins/mockPlugin"$'
|
||||
assertFileRegex home-files/.zshrc '^fpath+="$HOME/.zsh/plugins/mockPlugin"$'
|
||||
assertFileRegex home-files/.zshrc '^fpath+=("$HOME/.zsh/plugins/mockPlugin/share/zsh/site-functions" "$HOME/.zsh/plugins/mockPlugin/share/zsh/vendor-completions")$'
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue