fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . broot ; 8 9tomlFormat = pkgs . formats . toml { }; 10 11settingsModule = { 12freeformType = tomlFormat . type ; 13 14options = { 15modal = mkEnableOption "modal (vim) mode" ; 16 17verbs = mkOption { 18type = with types ; listOf ( attrsOf ( either bool str )); 19default = [ ]; 20example = literalExpression '' 21[ 22{ invocation = "p"; execution = ":parent"; } 23{ invocation = "edit"; shortcut = "e"; execution = "$EDITOR {file}" ; } 24{ invocation = "create {subpath}"; execution = "$EDITOR {directory}/{subpath}"; } 25{ invocation = "view"; execution = "less {file}"; } 26{ 27invocation = "blop {name}\\.{type}"; 28execution = "mkdir {parent}/{type} && ''${pkgs.neovim}/bin/nvim {parent}/{type}/{name}.{type}"; 29from_shell = true; 30} 31] 32'' ; 33description = '' 34Define new verbs. For more information, see 35[Verb Definition Attributes](https://dystroy.org/broot/documentation/configuration/#verb-definition-attributes) 36in the broot documentation. 37 38The possible attributes are: 39 40`invocation` (optional) 41: how the verb is called by the user, with placeholders for arguments 42 43`execution` (mandatory) 44: how the verb is executed 45 46`key` (optional) 47: a keyboard key triggering execution 48 49`shortcut` (optional) 50: an alternate way to call the verb (without 51the arguments part) 52 53`leave_broot` (optional) 54: whether to quit broot on execution 55(default: `true`) 56 57`from_shell` (optional)</term> 58: whether the verb must be executed from the 59parent shell (default: `false`) 60'' ; 61}; 62 63skin = mkOption { 64type = types . attrsOf types . str ; 65default = { }; 66example = literalExpression '' 67{ 68status_normal_fg = "grayscale(18)"; 69status_normal_bg = "grayscale(3)"; 70status_error_fg = "red"; 71status_error_bg = "yellow"; 72tree_fg = "red"; 73selected_line_bg = "grayscale(7)"; 74permissions_fg = "grayscale(12)"; 75size_bar_full_bg = "red"; 76size_bar_void_bg = "black"; 77directory_fg = "lightyellow"; 78input_fg = "cyan"; 79flag_value_fg = "lightyellow"; 80table_border_fg = "red"; 81code_fg = "lightyellow"; 82} 83'' ; 84description = '' 85Color configuration. 86 87Complete list of keys (expected to change before the v1 of broot): 88 89* `char_match` 90* `code` 91* `directory` 92* `exe` 93* `file` 94* `file_error` 95* `flag_label` 96* `flag_value` 97* `input` 98* `link` 99* `permissions` 100* `selected_line` 101* `size_bar_full` 102* `size_bar_void` 103* `size_text` 104* `spinner` 105* `status_error` 106* `status_normal` 107* `table_border` 108* `tree` 109* `unlisted` 110 111Add `_fg` for a foreground color and 112`_bg` for a background color. 113'' ; 114}; 115}; 116}; 117 118shellInit = shell : 119# Using mkAfter to make it more likely to appear after other 120# manipulations of the prompt. 121mkAfter '' 122source ${ 123pkgs . runCommand "br. ${ shell } " { nativeBuildInputs = [ cfg . package ]; } 124"broot --print-shell-function ${ shell } > $out" 125} 126'' ; 127in { 128meta . maintainers = [ hm . maintainers . aheaume maintainers . dermetfan ]; 129 130imports = [ 131( mkRenamedOptionModule [ "programs" "broot" "modal" ] [ 132"programs" 133"broot" 134"settings" 135"modal" 136]) 137( mkRenamedOptionModule [ "programs" "broot" "verbs" ] [ 138"programs" 139"broot" 140"settings" 141"verbs" 142]) 143( mkRenamedOptionModule [ "programs" "broot" "skin" ] [ 144"programs" 145"broot" 146"settings" 147"skin" 148]) 149]; 150 151options . programs . broot = { 152enable = mkEnableOption "Broot, a better way to navigate directories" ; 153 154enableBashIntegration = mkOption { 155default = true ; 156type = types . bool ; 157description = '' 158Whether to enable Bash integration. 159'' ; 160}; 161 162enableZshIntegration = mkOption { 163default = true ; 164type = types . bool ; 165description = '' 166Whether to enable Zsh integration. 167'' ; 168}; 169 170enableFishIntegration = mkOption { 171default = true ; 172type = types . bool ; 173description = '' 174Whether to enable Fish integration. 175'' ; 176}; 177 178package = mkOption { 179type = types . package ; 180default = pkgs . broot ; 181defaultText = literalExpression "pkgs.broot" ; 182description = "Package providing broot" ; 183}; 184 185settings = mkOption { 186type = types . submodule settingsModule ; 187default = { }; 188description = "Verbatim config entries" ; 189}; 190}; 191 192config = mkIf cfg . enable { 193home . packages = [ cfg . package ]; 194 195xdg . configFile . "broot" = { 196recursive = true ; 197source = pkgs . symlinkJoin { 198name = "xdg.configFile.broot" ; 199paths = [ 200# Copy all files under /resources/default-conf 201" ${ cfg . package . src } /resources/default-conf" 202 203# Dummy file to prevent broot from trying to reinstall itself 204( pkgs . writeTextDir "launcher/installed-v1" "" ) 205]; 206 207postBuild = '' 208ln -s ${ 209tomlFormat . generate "broot-config" cfg . settings 210} $ out /conf.toml 211 212# Remove conf.hjson, whose content has been merged into programs.broot.settings 213rm $ out /conf.hjson 214'' ; 215}; 216}; 217 218programs . broot . settings = builtins . fromJSON ( builtins . readFile 219( pkgs . runCommand "default-conf.json" { 220nativeBuildInputs = [ pkgs . hjson ]; 221} 222"hjson -c ${ cfg . package . src } /resources/default-conf/conf.hjson > $out" )); 223 224programs . bash . initExtra = mkIf cfg . enableBashIntegration ( shellInit "bash" ); 225 226programs . zsh . initExtra = mkIf cfg . enableZshIntegration ( shellInit "zsh" ); 227 228programs . fish . shellInit = mkIf cfg . enableFishIntegration ( shellInit "fish" ); 229}; 230}