fish: source event handling functions on shell init
Functions that contain event handler switches should be sourced during init, otherwise they become active only after being called manually.
This commit is contained in:
parent
77c47a4542
commit
b3ccd4bb26
3 changed files with 60 additions and 0 deletions
|
|
@ -397,6 +397,20 @@ let
|
|||
echo "end"
|
||||
echo "setup_hm_session_vars") > $out/${sessionVarsFile}
|
||||
'';
|
||||
sourceHandlersStr =
|
||||
let
|
||||
handlerAttrs = [
|
||||
"onJobExit"
|
||||
"onProcessExit"
|
||||
"onVariable"
|
||||
"onSignal"
|
||||
"onEvent"
|
||||
];
|
||||
isHandler = name: def: isAttrs def && builtins.any (attr: builtins.hasAttr attr def) handlerAttrs;
|
||||
handlerFunctions = lib.filterAttrs isHandler cfg.functions;
|
||||
sourceFunction = name: def: "source ${config.xdg.configHome}/fish/functions/${name}.fish";
|
||||
in
|
||||
builtins.concatStringsSep "\n" (lib.mapAttrsToList sourceFunction handlerFunctions);
|
||||
|
||||
in
|
||||
{
|
||||
|
|
@ -726,6 +740,9 @@ in
|
|||
|
||||
source ${cfg.sessionVariablesPackage}/${sessionVarsFile}
|
||||
|
||||
# Source handler functions
|
||||
${sourceHandlersStr}
|
||||
|
||||
${cfg.shellInit}
|
||||
|
||||
status is-login; and begin
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
fish-functions = ./functions.nix;
|
||||
fish-completions = ./completions.nix;
|
||||
fish-no-functions = ./no-functions.nix;
|
||||
fish-source-handlers = ./source-handlers.nix;
|
||||
fish-plugins = ./plugins.nix;
|
||||
fish-manpage = ./manpage.nix;
|
||||
fish-binds = ./binds.nix;
|
||||
|
|
|
|||
42
tests/modules/programs/fish/source-handlers.nix
Normal file
42
tests/modules/programs/fish/source-handlers.nix
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{ ... }:
|
||||
{
|
||||
config = {
|
||||
programs.fish = {
|
||||
enable = true;
|
||||
|
||||
functions = {
|
||||
normal-function = "";
|
||||
event-handler = {
|
||||
body = "";
|
||||
onEvent = "test";
|
||||
};
|
||||
variable-handler = {
|
||||
body = "";
|
||||
onVariable = "test";
|
||||
};
|
||||
job-handler = {
|
||||
body = "";
|
||||
onJobExit = "10";
|
||||
};
|
||||
signal-handler = {
|
||||
body = "";
|
||||
onSignal = "10";
|
||||
};
|
||||
process-handler = {
|
||||
body = "";
|
||||
onProcessExit = "10";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
nmt.script = ''
|
||||
assertFileExists home-files/.config/fish/config.fish
|
||||
assertFileContains home-files/.config/fish/config.fish "source /home/hm-user/.config/fish/functions/event-handler.fish"
|
||||
assertFileContains home-files/.config/fish/config.fish "source /home/hm-user/.config/fish/functions/variable-handler.fish"
|
||||
assertFileContains home-files/.config/fish/config.fish "source /home/hm-user/.config/fish/functions/job-handler.fish"
|
||||
assertFileContains home-files/.config/fish/config.fish "source /home/hm-user/.config/fish/functions/signal-handler.fish"
|
||||
assertFileContains home-files/.config/fish/config.fish "source /home/hm-user/.config/fish/functions/process-handler.fish"
|
||||
assertFileNotRegex home-files/.config/fish/config.fish "source /home/hm-user/.config/fish/functions/normal-function.fish"
|
||||
'';
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue