fork/home-manager
git clone https://git.julia.blue/fork/home-manager
406d34d9
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let cfg = config . programs . lf ; 6in { 7meta . maintainers = [ hm . maintainers . owm111 ]; 8 9options = { 10programs . lf = { 11enable = mkEnableOption "lf" ; 12 13package = mkOption { 14type = types . package ; 15default = pkgs . lf ; 16defaultText = literalExpression "pkgs.lf" ; 17description = '' 18lf package to use. 19'' ; 20}; 21 22settings = mkOption { 23type = with types ; 24attrsOf ( oneOf [ str int ( listOf ( either str int )) bool ]); 25default = { }; 26example = { 27tabstop = 4 ; 28number = true ; 29ratios = [ 1 1 2 ]; 30}; 31description = '' 32An attribute set of lf settings. See the lf documentation for 33detailed descriptions of these options. Prefer 34{option}`programs.lf.previewer.*` for setting lf's {var}`previewer` 35option. All string options are quoted with double quotes. 36'' ; 37}; 38 39commands = mkOption { 40type = with types ; attrsOf ( nullOr str ); 41default = { }; 42example = { 43get-mime-type = ''%xdg-mime query filetype "$f"'' ; 44open = "$$OPENER $f" ; 45}; 46description = '' 47Commands to declare. Commands set to null or an empty string are 48deleted. 49'' ; 50}; 51 52keybindings = mkOption { 53type = with types ; attrsOf ( nullOr str ); 54default = { }; 55example = { 56gh = "cd ~" ; 57D = "trash" ; 58i = "$less $f" ; 59U = "!du -sh" ; 60gg = null ; 61}; 62description = 63"Keys to bind. Keys set to null or an empty string are deleted." ; 64}; 65 66cmdKeybindings = mkOption { 67type = with types ; attrsOf ( nullOr str ); 68default = { }; 69example = literalExpression ''{ "<c-g>" = "cmd-escape"; }'' ; 70description = '' 71Keys to bind to command line commands which can only be one of the 72builtin commands. Keys set to null or an empty string are deleted. 73'' ; 74}; 75 76previewer . source = mkOption { 77type = with types ; nullOr path ; 78default = null ; 79example = literalExpression '' 80pkgs.writeShellScript "pv.sh" ''' 81#!/bin/sh 82 83case "$1" in 84*.tar*) tar tf "$1";; 85*.zip) unzip -l "$1";; 86*.rar) unrar l "$1";; 87*.7z) 7z l "$1";; 88*.pdf) pdftotext "$1" -;; 89*) highlight -O ansi "$1" || cat "$1";; 90esac 91''' 92'' ; 93description = '' 94Script or executable to use to preview files. Sets lf's 95{var}`previewer` option. 96'' ; 97}; 98 99previewer . keybinding = mkOption { 100type = with types ; nullOr str ; 101default = null ; 102example = "i" ; 103description = '' 104Key to bind to the script at {var}`previewer.source` and 105pipe through less. Setting to null will not bind any key. 106'' ; 107}; 108 109extraConfig = mkOption { 110type = types . lines ; 111default = "" ; 112example = '' 113$mkdir -p ~/.trash 114'' ; 115description = "Custom lfrc lines." ; 116}; 117}; 118}; 119 120config = mkIf cfg . enable { 121home . packages = [ cfg . package ]; 122 123xdg . configFile . "lf/lfrc" . text = let 124fmtSetting = k :v : 125optionalString ( v != null ) "set ${ 126if isBool v then 127" ${ optionalString ( ! v ) "no" }${ k } " 128else if isList v then 129'' ${ k } " ${ concatStringsSep ":" ( map ( w : toString w ) v )} "'' 130else 131" ${ k } ${ if isInt v then toString v else ''" ${ v } "'' } " 132} " ; 133 134settingsStr = concatStringsSep "\n" 135( remove "" ( mapAttrsToList fmtSetting cfg . settings )); 136 137fmtCmdMap = before :k :v : 138" ${ before } ${ k }${ optionalString ( v != null && v != "" ) " ${ v } " } " ; 139fmtCmd = fmtCmdMap "cmd" ; 140fmtMap = fmtCmdMap "map" ; 141fmtCmap = fmtCmdMap "cmap" ; 142 143commandsStr = concatStringsSep "\n" ( mapAttrsToList fmtCmd cfg . commands ); 144keybindingsStr = 145concatStringsSep "\n" ( mapAttrsToList fmtMap cfg . keybindings ); 146cmdKeybindingsStr = 147concatStringsSep "\n" ( mapAttrsToList fmtCmap cfg . cmdKeybindings ); 148 149previewerStr = optionalString ( cfg . previewer . source != null ) '' 150set previewer ${ cfg . previewer . source } 151${ optionalString ( cfg . previewer . keybinding != null ) '' 152map ${ cfg . previewer . keybinding } ''$ ${ cfg . previewer . source } "$f" | less -R 153'' } 154'' ; 155in '' 156${ settingsStr } 157 158${ commandsStr } 159 160${ keybindingsStr } 161 162${ cmdKeybindingsStr } 163 164${ previewerStr } 165 166${ cfg . extraConfig } 167'' ; 168}; 169}