1{ lib, writeShellApplication, fish, writeTextFile }:
2
3lib.makeOverridable ({
4 completionDirs ? [],
5 functionDirs ? [],
6 confDirs ? [],
7 pluginPkgs ? [],
8 localConfig ? "",
9 shellAliases ? {},
10 runtimeInputs ? []
11}:
12
13let
14 aliasesStr = builtins.concatStringsSep "\n"
15 (lib.mapAttrsToList (k: v: "alias ${k} ${lib.escapeShellArg v}") shellAliases);
16
17 shellAliasesFishConfig = writeTextFile {
18 name = "wrapfish.aliases.fish";
19 destination = "/share/fish/vendor_conf.d/aliases.fish";
20 text = ''
21 status --is-interactive; and begin
22 # Aliases
23 ${aliasesStr}
24 end
25 '';
26 };
27
28 localFishConfig = writeTextFile {
29 name = "wrapfish.local.fish";
30 destination = "/share/fish/vendor_conf.d/config.local.fish";
31 text = localConfig;
32 };
33
34 vendorDir = kind: plugin: "${plugin}/share/fish/vendor_${kind}.d";
35 complPath = completionDirs ++ map (vendorDir "completions") pluginPkgs;
36 funcPath = functionDirs ++ map (vendorDir "functions") pluginPkgs;
37 confPath = confDirs
38 ++ (map (vendorDir "conf") pluginPkgs)
39 ++ (map (vendorDir "conf") [ localFishConfig shellAliasesFishConfig ]);
40
41in writeShellApplication {
42 inherit runtimeInputs;
43 name = "fish";
44 text = ''
45 ${fish}/bin/fish --init-command "
46 set --prepend fish_complete_path ${lib.escapeShellArgs complPath}
47 set --prepend fish_function_path ${lib.escapeShellArgs funcPath}
48 set --local fish_conf_source_path ${lib.escapeShellArgs confPath}
49 for c in \$fish_conf_source_path/*; source \$c; end
50 " "$@"
51 '';
52})