fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert Helgessonhome-manager: i18n fixesb62f5496

master
3.0 KiB100 linesraw
1{ config, pkgs, lib, ... }:
2
3let
4
5  inherit (lib)
6    mkEnableOption mkPackageOption mkIf pipe fileContents splitString;
7  cfg = config.programs.carapace;
8  bin = cfg.package + "/bin/carapace";
9
10in {
11  meta.maintainers = with lib.maintainers; [ weathercold bobvanderlinden ];
12
13  options.programs.carapace = {
14    enable =
15      mkEnableOption "carapace, a multi-shell multi-command argument completer";
16
17    package = mkPackageOption pkgs "carapace" { };
18
19    enableBashIntegration = mkEnableOption "Bash integration" // {
20      default = true;
21    };
22
23    enableZshIntegration = mkEnableOption "Zsh integration" // {
24      default = true;
25    };
26
27    enableFishIntegration = mkEnableOption "Fish integration" // {
28      default = true;
29    };
30
31    enableNushellIntegration = mkEnableOption "Nushell integration" // {
32      default = true;
33    };
34  };
35
36  config = mkIf cfg.enable {
37    home.packages = [ cfg.package ];
38
39    programs = {
40      bash.initExtra = mkIf cfg.enableBashIntegration ''
41        source <(${bin} _carapace bash)
42      '';
43
44      zsh.initExtra = mkIf cfg.enableZshIntegration ''
45        source <(${bin} _carapace zsh)
46      '';
47
48      fish.interactiveShellInit = mkIf cfg.enableFishIntegration ''
49        ${bin} _carapace fish | source
50      '';
51
52      nushell = mkIf cfg.enableNushellIntegration {
53        # Note, the ${"$"} below is a work-around because xgettext otherwise
54        # interpret it as a Bash i18n string.
55        extraEnv = ''
56          let carapace_cache = "${config.xdg.cacheHome}/carapace"
57          if not ($carapace_cache | path exists) {
58            mkdir $carapace_cache
59          }
60          ${bin} _carapace nushell | save -f ${"$"}"($carapace_cache)/init.nu"
61        '';
62        extraConfig = ''
63          source ${config.xdg.cacheHome}/carapace/init.nu
64        '';
65      };
66    };
67
68    xdg.configFile =
69      mkIf (config.programs.fish.enable && cfg.enableFishIntegration) (
70        # Convert the entries from `carapace --list` to empty
71        # xdg.configFile."fish/completions/NAME.fish" entries.
72        #
73        # This is to disable fish builtin completion for each of the
74        # carapace-supported completions It is in line with the instructions from
75        # carapace-bin:
76        #
77        #   carapace --list | awk '{print $1}' | xargs -I{} touch ~/.config/fish/completions/{}.fish
78        #
79        # See https://github.com/rsteube/carapace-bin#getting-started
80        let
81          carapaceListFile = pkgs.runCommandLocal "carapace-list" {
82            buildInputs = [ cfg.package ];
83          } ''
84            ${bin} --list > $out
85          '';
86        in pipe carapaceListFile [
87          fileContents
88          (splitString "\n")
89          (map (builtins.match "^([a-z0-9-]+) .*"))
90          (builtins.filter
91            (match: match != null && (builtins.length match) > 0))
92          (map (match: builtins.head match))
93          (map (name: {
94            name = "fish/completions/${name}.fish";
95            value = { text = ""; };
96          }))
97          builtins.listToAttrs
98        ]);
99  };
100}