From 1806e5511efb06cd64c4bdd4e0a98ab1b5ad1542 Mon Sep 17 00:00:00 2001 From: Olli Helenius Date: Sun, 14 Apr 2019 13:49:55 +0300 Subject: [PATCH] skim: add module --- modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/skim.nix | 128 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 modules/programs/skim.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index f9b5eba71..0083b661a 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1051,6 +1051,13 @@ in breaking your configuration! ''; } + + { + time = "2019-04-14T15:35:16+00:00"; + message = '' + A new module is available: 'programs.skim'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 9153bb262..4822f8428 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -75,6 +75,7 @@ let (loadModule ./programs/opam.nix { }) (loadModule ./programs/pidgin.nix { }) (loadModule ./programs/rofi.nix { }) + (loadModule ./programs/skim.nix { }) (loadModule ./programs/ssh.nix { }) (loadModule ./programs/taskwarrior.nix { }) (loadModule ./programs/termite.nix { }) diff --git a/modules/programs/skim.nix b/modules/programs/skim.nix new file mode 100644 index 000000000..4b8f8ee37 --- /dev/null +++ b/modules/programs/skim.nix @@ -0,0 +1,128 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.skim; + +in + +{ + 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; + default = []; + 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; + default = []; + example = [ "--preview 'head {}'" ]; + description = '' + Command line options for the CTRL-T keybinding. + ''; + }; + + changeDirWidgetCommand = mkOption { + type = types.nullOr types.str; + default = null; + example = "fd --type d" ; + description = '' + The command that gets executed as the source for skim for the + ALT-C keybinding. + ''; + }; + + changeDirWidgetOptions = mkOption { + type = types.listOf types.str; + default = []; + example = [ "--preview 'tree -C {} | head -200'" ]; + description = '' + Command line options for the ALT-C keybinding. + ''; + }; + + historyWidgetOptions = mkOption { + type = types.listOf types.str; + default = []; + 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. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.skim ]; + + 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_OPTS = cfg.defaultOptions; + } + ); + + 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 + ''; + }; +}