1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2025-01-30 12:55:02 +01:00

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:
MrTipson 2024-12-15 00:28:43 +01:00
parent 66c5d8b628
commit b8da5337cc
3 changed files with 56 additions and 0 deletions

View file

@ -228,6 +228,15 @@ let
echo "end"
echo "setup_hm_session_vars") > $out
'';
sourceHandlersStr = let
handlerAttrs =
[ "onJobExit" "onProcessExit" "onVariable" "onSignal" "onEvent" ];
isHandler = name: def:
isAttrs def && any (attr: hasAttr attr def) handlerAttrs;
handlerFunctions = filterAttrs isHandler cfg.functions;
sourceFunction = name: def:
"source ${config.xdg.configHome}/fish/functions/${name}.fish";
in concatStringsSep "\n" (mapAttrsToList sourceFunction handlerFunctions);
in {
imports = [
@ -475,6 +484,9 @@ in {
source ${translatedSessionVariables}
# Source handler functions
${sourceHandlersStr}
${cfg.shellInit}
status is-login; and begin

View file

@ -3,5 +3,6 @@
fish-format-scripts = ./format-scripts.nix;
fish-functions = ./functions.nix;
fish-no-functions = ./no-functions.nix;
fish-source-handlers = ./source-handlers.nix;
fish-plugins = ./plugins.nix;
}

View file

@ -0,0 +1,43 @@
{ config, lib, pkgs, ... }:
with builtins; {
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"
'';
};
}