fork/home-manager

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

Robert HelgessonMerge PR #421575790441

master
3.7 KiB143 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.programs.skim;
8
9in {
10  options.programs.skim = {
11    enable = mkEnableOption "skim - a command-line fuzzy finder";
12
13    package = mkOption {
14      type = types.package;
15      default = pkgs.skim;
16      defaultText = literalExpression "pkgs.skim";
17      description = "Package providing the {command}`skim` tool.";
18    };
19
20    defaultCommand = mkOption {
21      type = types.nullOr types.str;
22      default = null;
23      example = "fd --type f";
24      description = ''
25        The command that gets executed as the default source for skim
26        when running.
27      '';
28    };
29
30    defaultOptions = mkOption {
31      type = types.listOf types.str;
32      default = [ ];
33      example = [ "--height 40%" "--prompt ⟫" ];
34      description = ''
35        Extra command line options given to skim by default.
36      '';
37    };
38
39    fileWidgetCommand = mkOption {
40      type = types.nullOr types.str;
41      default = null;
42      example = "fd --type f";
43      description = ''
44        The command that gets executed as the source for skim for the
45        CTRL-T keybinding.
46      '';
47    };
48
49    fileWidgetOptions = mkOption {
50      type = types.listOf types.str;
51      default = [ ];
52      example = [ "--preview 'head {}'" ];
53      description = ''
54        Command line options for the CTRL-T keybinding.
55      '';
56    };
57
58    changeDirWidgetCommand = mkOption {
59      type = types.nullOr types.str;
60      default = null;
61      example = "fd --type d";
62      description = ''
63        The command that gets executed as the source for skim for the
64        ALT-C keybinding.
65      '';
66    };
67
68    changeDirWidgetOptions = mkOption {
69      type = types.listOf types.str;
70      default = [ ];
71      example = [ "--preview 'tree -C {} | head -200'" ];
72      description = ''
73        Command line options for the ALT-C keybinding.
74      '';
75    };
76
77    historyWidgetOptions = mkOption {
78      type = types.listOf types.str;
79      default = [ ];
80      example = [ "--tac" "--exact" ];
81      description = ''
82        Command line options for the CTRL-R keybinding.
83      '';
84    };
85
86    enableBashIntegration = mkOption {
87      default = true;
88      type = types.bool;
89      description = ''
90        Whether to enable Bash integration.
91      '';
92    };
93
94    enableZshIntegration = mkOption {
95      default = true;
96      type = types.bool;
97      description = ''
98        Whether to enable Zsh integration.
99      '';
100    };
101
102    enableFishIntegration = mkOption {
103      default = true;
104      type = types.bool;
105      description = ''
106        Whether to enable Fish integration.
107      '';
108    };
109  };
110
111  config = mkIf cfg.enable {
112    home.packages = [ cfg.package ];
113
114    home.sessionVariables = mapAttrs (n: v: toString v)
115      (filterAttrs (n: v: v != [ ] && v != null) {
116        SKIM_ALT_C_COMMAND = cfg.changeDirWidgetCommand;
117        SKIM_ALT_C_OPTS = cfg.changeDirWidgetOptions;
118        SKIM_CTRL_R_OPTS = cfg.historyWidgetOptions;
119        SKIM_CTRL_T_COMMAND = cfg.fileWidgetCommand;
120        SKIM_CTRL_T_OPTS = cfg.fileWidgetOptions;
121        SKIM_DEFAULT_COMMAND = cfg.defaultCommand;
122        SKIM_DEFAULT_OPTIONS = cfg.defaultOptions;
123      });
124
125    programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
126      if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
127        . ${cfg.package}/share/skim/completion.bash
128        . ${cfg.package}/share/skim/key-bindings.bash
129      fi
130    '';
131
132    programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
133      if [[ $options[zle] = on ]]; then
134        . ${cfg.package}/share/skim/completion.zsh
135        . ${cfg.package}/share/skim/key-bindings.zsh
136      fi
137    '';
138
139    programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
140      source ${cfg.package}/share/skim/key-bindings.fish && skim_key_bindings
141    '';
142  };
143}