mirror of
https://github.com/nix-community/home-manager.git
synced 2024-12-14 11:57:55 +00:00
fish: install plugin files
Fish plugin files are now installed directly into the config directory instead of being sourced. This is needed because sourcing breaks attaching event listeners using `functions --query`, which sponge requires for example.
This commit is contained in:
parent
b3d5ea65d8
commit
64f05a5771
1 changed files with 35 additions and 75 deletions
|
@ -6,29 +6,6 @@ let
|
|||
|
||||
cfg = config.programs.fish;
|
||||
|
||||
pluginModule = types.submodule ({ config, ... }: {
|
||||
options = {
|
||||
src = mkOption {
|
||||
type = types.path;
|
||||
description = ''
|
||||
Path to the plugin folder.
|
||||
|
||||
Relevant pieces will be added to the fish function path and
|
||||
the completion path. The {file}`init.fish` and
|
||||
{file}`key_binding.fish` files are sourced if
|
||||
they exist.
|
||||
'';
|
||||
};
|
||||
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
description = ''
|
||||
The name of the plugin.
|
||||
'';
|
||||
};
|
||||
};
|
||||
});
|
||||
|
||||
functionModule = types.submodule {
|
||||
options = {
|
||||
body = mkOption {
|
||||
|
@ -326,36 +303,36 @@ in {
|
|||
};
|
||||
|
||||
programs.fish.plugins = mkOption {
|
||||
type = types.listOf pluginModule;
|
||||
type = types.listOf types.path;
|
||||
default = [ ];
|
||||
example = literalExpression ''
|
||||
[
|
||||
{
|
||||
name = "z";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
(pkgs.fetchFromGitHub {
|
||||
owner = "jethrokuan";
|
||||
repo = "z";
|
||||
rev = "ddeb28a7b6a1f0ec6dae40c636e5ca4908ad160a";
|
||||
sha256 = "0c5i7sdrsp0q3vbziqzdyqn4fmp235ax4mn4zslrswvn8g3fvdyh";
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
# oh-my-fish plugins are stored in their own repositories, which
|
||||
# makes them simple to import into home-manager.
|
||||
{
|
||||
name = "fasd";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
(pkgs.fetchFromGitHub {
|
||||
owner = "oh-my-fish";
|
||||
repo = "plugin-fasd";
|
||||
rev = "38a5b6b6011106092009549e52249c6d6f501fba";
|
||||
sha256 = "06v37hqy5yrv5a6ssd1p3cjd9y3hnp19d3ab7dag56fs1qmgyhbs";
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
pkgs.fishPlugins.tide.src
|
||||
]
|
||||
'';
|
||||
description = ''
|
||||
The plugins to source in
|
||||
{file}`conf.d/99plugins.fish`.
|
||||
The plugins to install.
|
||||
|
||||
It's important to pass the source files directly,
|
||||
instead of the derivations in nixpkgs. You can still
|
||||
use plugins from nixpkgs by accessing their `src` attribute,
|
||||
as seen in the example.
|
||||
'';
|
||||
};
|
||||
|
||||
|
@ -516,37 +493,20 @@ in {
|
|||
# Each plugin gets a corresponding conf.d/plugin-NAME.fish file to load
|
||||
# in the paths and any initialization scripts.
|
||||
(mkIf (length cfg.plugins > 0) {
|
||||
xdg.configFile = mkMerge ((map (plugin: {
|
||||
"fish/conf.d/plugin-${plugin.name}.fish".source =
|
||||
fishIndent "${plugin.name}.fish" ''
|
||||
# Plugin ${plugin.name}
|
||||
set -l plugin_dir ${plugin.src}
|
||||
|
||||
# Set paths to import plugin components
|
||||
if test -d $plugin_dir/functions
|
||||
set fish_function_path $fish_function_path[1] $plugin_dir/functions $fish_function_path[2..-1]
|
||||
end
|
||||
|
||||
if test -d $plugin_dir/completions
|
||||
set fish_complete_path $fish_complete_path[1] $plugin_dir/completions $fish_complete_path[2..-1]
|
||||
end
|
||||
|
||||
# Source initialization code if it exists.
|
||||
if test -d $plugin_dir/conf.d
|
||||
for f in $plugin_dir/conf.d/*.fish
|
||||
source $f
|
||||
end
|
||||
end
|
||||
|
||||
if test -f $plugin_dir/key_bindings.fish
|
||||
source $plugin_dir/key_bindings.fish
|
||||
end
|
||||
|
||||
if test -f $plugin_dir/init.fish
|
||||
source $plugin_dir/init.fish
|
||||
end
|
||||
'';
|
||||
}) cfg.plugins));
|
||||
xdg.configFile = mkMerge (flatten (map (src:
|
||||
let
|
||||
mkPluginConfig = src: dir:
|
||||
let path = "${src}/${dir}";
|
||||
in if pathExists path then
|
||||
map (file: { "fish/${dir}/${file}".source = "${path}/${file}"; })
|
||||
(attrNames (builtins.readDir path))
|
||||
else
|
||||
[ ];
|
||||
in [
|
||||
(mkPluginConfig src "functions")
|
||||
(mkPluginConfig src "completions")
|
||||
(mkPluginConfig src "conf.d")
|
||||
]) cfg.plugins));
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue