mirror of
https://github.com/nix-community/home-manager
synced 2025-01-30 21:05: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:
parent
66c5d8b628
commit
b8da5337cc
3 changed files with 56 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
43
tests/modules/programs/fish/source-handlers.nix
Normal file
43
tests/modules/programs/fish/source-handlers.nix
Normal 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"
|
||||
'';
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue