1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-24 12:09:46 +01:00
home-manager/modules/programs/skim.nix

137 lines
3.5 KiB
Nix
Raw Normal View History

2019-04-14 12:49:55 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.skim;
2020-02-02 00:39:17 +01:00
in {
2019-04-14 12:49:55 +02:00
options.programs.skim = {
enable = mkEnableOption "skim - a command-line fuzzy finder";
defaultCommand = mkOption {
type = types.nullOr types.str;
default = null;
example = "fd --type f";
description = ''
The command that gets executed as the default source for skim
when running.
'';
};
defaultOptions = mkOption {
type = types.listOf types.str;
2020-02-02 00:39:17 +01:00
default = [ ];
2019-04-14 12:49:55 +02:00
example = [ "--height 40%" "--prompt " ];
description = ''
Extra command line options given to skim by default.
'';
};
fileWidgetCommand = mkOption {
type = types.nullOr types.str;
default = null;
example = "fd --type f";
description = ''
The command that gets executed as the source for skim for the
CTRL-T keybinding.
'';
};
fileWidgetOptions = mkOption {
type = types.listOf types.str;
2020-02-02 00:39:17 +01:00
default = [ ];
2019-04-14 12:49:55 +02:00
example = [ "--preview 'head {}'" ];
description = ''
Command line options for the CTRL-T keybinding.
'';
};
changeDirWidgetCommand = mkOption {
type = types.nullOr types.str;
default = null;
2020-02-02 00:39:17 +01:00
example = "fd --type d";
2019-04-14 12:49:55 +02:00
description = ''
The command that gets executed as the source for skim for the
ALT-C keybinding.
'';
};
changeDirWidgetOptions = mkOption {
type = types.listOf types.str;
2020-02-02 00:39:17 +01:00
default = [ ];
2019-04-14 12:49:55 +02:00
example = [ "--preview 'tree -C {} | head -200'" ];
description = ''
Command line options for the ALT-C keybinding.
'';
};
historyWidgetOptions = mkOption {
type = types.listOf types.str;
2020-02-02 00:39:17 +01:00
default = [ ];
2019-04-14 12:49:55 +02:00
example = [ "--tac" "--exact" ];
description = ''
Command line options for the CTRL-R keybinding.
'';
};
enableBashIntegration = mkOption {
default = true;
type = types.bool;
description = ''
Whether to enable Bash integration.
'';
};
enableZshIntegration = mkOption {
default = true;
type = types.bool;
description = ''
Whether to enable Zsh integration.
'';
};
enableFishIntegration = mkOption {
default = true;
type = types.bool;
description = ''
Whether to enable Fish integration.
'';
};
2019-04-14 12:49:55 +02:00
};
config = mkIf cfg.enable {
home.packages = [ pkgs.skim ];
2020-02-02 00:39:17 +01:00
home.sessionVariables = mapAttrs (n: v: toString v)
(filterAttrs (n: v: v != [ ] && v != null) {
SKIM_ALT_C_COMMAND = cfg.changeDirWidgetCommand;
SKIM_ALT_C_OPTS = cfg.changeDirWidgetOptions;
SKIM_CTRL_R_OPTS = cfg.historyWidgetOptions;
SKIM_CTRL_T_COMMAND = cfg.fileWidgetCommand;
SKIM_CTRL_T_OPTS = cfg.fileWidgetOptions;
SKIM_DEFAULT_COMMAND = cfg.defaultCommand;
SKIM_DEFAULT_OPTIONS = cfg.defaultOptions;
});
2019-04-14 12:49:55 +02:00
programs.bash.initExtra = mkIf cfg.enableBashIntegration ''
if [[ :$SHELLOPTS: =~ :(vi|emacs): ]]; then
. ${pkgs.skim}/share/skim/completion.bash
. ${pkgs.skim}/share/skim/key-bindings.bash
fi
'';
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
if [[ $options[zle] = on ]]; then
. ${pkgs.skim}/share/skim/completion.zsh
. ${pkgs.skim}/share/skim/key-bindings.zsh
fi
'';
programs.fish.shellInit = mkIf cfg.enableFishIntegration ''
source ${pkgs.skim}/share/skim/key-bindings.fish && skim_key_bindings
'';
2019-04-14 12:49:55 +02:00
};
}