diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 945e1d427..6cd830fe4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -84,7 +84,7 @@ Makefile @thiagokokada /modules/programs/bottom.nix @polykernel /tests/modules/programs/bottom @polykernel -/modules/programs/broot.nix @aheaume +/modules/programs/broot.nix @aheaume @dermetfan /modules/programs/btop.nix @GaetanLepage /tests/modules/programs/btop.nix @GaetanLepage diff --git a/docs/release-notes/rl-2105.adoc b/docs/release-notes/rl-2105.adoc index 7fcfb268d..ed94f8880 100644 --- a/docs/release-notes/rl-2105.adoc +++ b/docs/release-notes/rl-2105.adoc @@ -8,7 +8,7 @@ The 21.05 release branch became the stable branch in May, 2021. This release has the following notable changes: -* The <> option is now a list rather than an +* The `opt-programs.broot.verbs` option is now a list rather than an attribute set. To migrate, move the keys of the attrset into the list items' `invocation` keys. For example, + diff --git a/modules/programs/broot.nix b/modules/programs/broot.nix index f37470d7c..5197c8484 100644 --- a/modules/programs/broot.nix +++ b/modules/programs/broot.nix @@ -8,15 +8,160 @@ let tomlFormat = pkgs.formats.toml { }; - brootConf = { - verbs = cfg.verbs; - skin = cfg.skin; - modal = cfg.modal; + settingsModule = { + freeformType = tomlFormat.type; + + options = { + modal = mkEnableOption "modal (vim) mode"; + + verbs = mkOption { + type = with types; listOf (attrsOf (either bool str)); + default = [ ]; + example = literalExpression '' + [ + { invocation = "p"; execution = ":parent"; } + { invocation = "edit"; shortcut = "e"; execution = "$EDITOR {file}" ; } + { invocation = "create {subpath}"; execution = "$EDITOR {directory}/{subpath}"; } + { invocation = "view"; execution = "less {file}"; } + { + invocation = "blop {name}\\.{type}"; + execution = "mkdir {parent}/{type} && ''${pkgs.neovim}/bin/nvim {parent}/{type}/{name}.{type}"; + from_shell = true; + } + ] + ''; + description = '' + Define new verbs. For more information, see + . + + The possible attributes are: + + + + + + invocation (optional) + how the verb is called by the user, with placeholders for arguments + + + execution (mandatory) + how the verb is executed + + + key (optional) + a keyboard key triggering execution + + + shortcut (optional) + an alternate way to call the verb (without + the arguments part) + + + leave_broot (optional) + whether to quit broot on execution + (default: true) + + + from_shell (optional) + whether the verb must be executed from the + parent shell (default: + false) + + + ''; + }; + + skin = mkOption { + type = types.attrsOf types.str; + default = { }; + example = literalExpression '' + { + status_normal_fg = "grayscale(18)"; + status_normal_bg = "grayscale(3)"; + status_error_fg = "red"; + status_error_bg = "yellow"; + tree_fg = "red"; + selected_line_bg = "grayscale(7)"; + permissions_fg = "grayscale(12)"; + size_bar_full_bg = "red"; + size_bar_void_bg = "black"; + directory_fg = "lightyellow"; + input_fg = "cyan"; + flag_value_fg = "lightyellow"; + table_border_fg = "red"; + code_fg = "lightyellow"; + } + ''; + description = '' + Color configuration. + + Complete list of keys (expected to change before the v1 of broot): + + + char_match + code + directory + exe + file + file_error + flag_label + flag_value + input + link + permissions + selected_line + size_bar_full + size_bar_void + size_text + spinner + status_error + status_normal + table_border + tree + unlisted + + + + Add _fg for a foreground color and + _bg for a background colors. + ''; + }; + }; }; + shellInit = shell: + # Using mkAfter to make it more likely to appear after other + # manipulations of the prompt. + mkAfter '' + source ${ + pkgs.runCommand "br.${shell}" { nativeBuildInputs = [ cfg.package ]; } + "broot --print-shell-function ${shell} > $out" + } + ''; in { meta.maintainers = [ hm.maintainers.aheaume ]; + imports = [ + (mkRenamedOptionModule [ "programs" "broot" "modal" ] [ + "programs" + "broot" + "settings" + "modal" + ]) + (mkRenamedOptionModule [ "programs" "broot" "verbs" ] [ + "programs" + "broot" + "settings" + "verbs" + ]) + (mkRenamedOptionModule [ "programs" "broot" "skin" ] [ + "programs" + "broot" + "settings" + "skin" + ]) + ]; + options.programs.broot = { enable = mkEnableOption "Broot, a better way to navigate directories"; @@ -44,83 +189,6 @@ in { ''; }; - modal = mkEnableOption "modal (vim) mode"; - - verbs = mkOption { - type = with types; listOf (attrsOf (either bool str)); - default = [ - { - invocation = "p"; - execution = ":parent"; - } - { - invocation = "edit"; - shortcut = "e"; - execution = "$EDITOR {file}"; - } - { - invocation = "create {subpath}"; - execution = "$EDITOR {directory}/{subpath}"; - } - { - invocation = "view"; - execution = "less {file}"; - } - ]; - example = literalExpression '' - [ - { invocation = "p"; execution = ":parent"; } - { invocation = "edit"; shortcut = "e"; execution = "$EDITOR {file}" ; } - { invocation = "create {subpath}"; execution = "$EDITOR {directory}/{subpath}"; } - { invocation = "view"; execution = "less {file}"; } - { - invocation = "blop {name}\\.{type}"; - execution = "/bin/mkdir {parent}/{type} && /usr/bin/nvim {parent}/{type}/{name}.{type}"; - from_shell = true; - } - ] - ''; - description = '' - Define new verbs. For more information, see - . - - The possible attributes are: - - - - - - invocation (optional) - how the verb is called by the user, with placeholders for arguments - - - execution (mandatory) - how the verb is executed - - - key (optional) - a keyboard key triggering execution - - - shortcut (optional) - an alternate way to call the verb (without - the arguments part) - - - leave_broot (optional) - whether to quit broot on execution - (default: true) - - - from_shell (optional) - whether the verb must be executed from the - parent shell (default: - false) - - - ''; - }; - package = mkOption { type = types.package; default = pkgs.broot; @@ -128,60 +196,10 @@ in { description = "Package providing broot"; }; - skin = mkOption { - type = types.attrsOf types.str; + settings = mkOption { + type = types.submodule settingsModule; default = { }; - example = literalExpression '' - { - status_normal_fg = "grayscale(18)"; - status_normal_bg = "grayscale(3)"; - status_error_fg = "red"; - status_error_bg = "yellow"; - tree_fg = "red"; - selected_line_bg = "grayscale(7)"; - permissions_fg = "grayscale(12)"; - size_bar_full_bg = "red"; - size_bar_void_bg = "black"; - directory_fg = "lightyellow"; - input_fg = "cyan"; - flag_value_fg = "lightyellow"; - table_border_fg = "red"; - code_fg = "lightyellow"; - } - ''; - description = '' - Color configuration. - - Complete list of keys (expected to change before the v1 of broot): - - - char_match - code - directory - exe - file - file_error - flag_label - flag_value - input - link - permissions - selected_line - size_bar_full - size_bar_void - size_text - spinner - status_error - status_normal - table_border - tree - unlisted - - - - Add _fg for a foreground color and - _bg for a background colors. - ''; + description = "Verbatim config entries"; }; }; @@ -189,88 +207,20 @@ in { home.packages = [ cfg.package ]; xdg.configFile."broot/conf.toml".source = - tomlFormat.generate "broot-config" brootConf; + tomlFormat.generate "broot-config" cfg.settings; # Dummy file to prevent broot from trying to reinstall itself xdg.configFile."broot/launcher/installed-v1".text = ""; - programs.bash.initExtra = mkIf cfg.enableBashIntegration ( - # Using mkAfter to make it more likely to appear after other - # manipulations of the prompt. - mkAfter '' - # This script was automatically generated by the broot function - # More information can be found in https://github.com/Canop/broot - # This function starts broot and executes the command - # it produces, if any. - # It's needed because some shell commands, like `cd`, - # have no useful effect if executed in a subshell. - function br { - f=$(mktemp) - ( - set +e - broot --outcmd "$f" "$@" - code=$? - if [ "$code" != 0 ]; then - rm -f "$f" - exit "$code" - fi - ) - code=$? - if [ "$code" != 0 ]; then - return "$code" - fi - d=$(cat "$f") - rm -f "$f" - eval "$d" - } - ''); + programs.broot.settings = builtins.fromJSON (builtins.readFile + (pkgs.runCommand "default-conf.json" { + nativeBuildInputs = [ pkgs.hjson ]; + } "hjson -c ${cfg.package.src}/resources/default-conf.hjson > $out")); - programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' - # This script was automatically generated by the broot function - # More information can be found in https://github.com/Canop/broot - # This function starts broot and executes the command - # it produces, if any. - # It's needed because some shell commands, like `cd`, - # have no useful effect if executed in a subshell. - function br { - f=$(mktemp) - ( - set +e - broot --outcmd "$f" "$@" - code=$? - if [ "$code" != 0 ]; then - rm -f "$f" - exit "$code" - fi - ) - code=$? - if [ "$code" != 0 ]; then - return "$code" - fi - d=$(cat "$f") - rm -f "$f" - eval "$d" - } - ''; + programs.bash.initExtra = mkIf cfg.enableBashIntegration (shellInit "bash"); - programs.fish.shellInit = mkIf cfg.enableFishIntegration '' - # This script was automatically generated by the broot function - # More information can be found in https://github.com/Canop/broot - # This function starts broot and executes the command - # it produces, if any. - # It's needed because some shell commands, like `cd`, - # have no useful effect if executed in a subshell. - function br - set f (mktemp) - broot --outcmd $f $argv - if test $status -ne 0 - rm -f "$f" - return "$code" - end - set d (cat "$f") - rm -f "$f" - eval "$d" - end - ''; + programs.zsh.initExtra = mkIf cfg.enableZshIntegration (shellInit "zsh"); + + programs.fish.shellInit = mkIf cfg.enableFishIntegration (shellInit "fish"); }; } diff --git a/tests/modules/programs/broot/broot.nix b/tests/modules/programs/broot/broot.nix index a2dddca38..58a281083 100644 --- a/tests/modules/programs/broot/broot.nix +++ b/tests/modules/programs/broot/broot.nix @@ -6,33 +6,46 @@ with lib; config = { programs.broot = { enable = true; - modal = true; + settings.modal = true; }; - test.stubs.broot = { }; - nmt.script = '' assertFileExists home-files/.config/broot/conf.toml assertFileContent home-files/.config/broot/conf.toml ${ pkgs.writeText "broot.expected" '' modal = true + show_selection_mark = true [[verbs]] - execution = ":parent" - invocation = "p" - - [[verbs]] - execution = "$EDITOR {file}" + execution = "$EDITOR +{line} {file}" invocation = "edit" + leave_broot = false shortcut = "e" [[verbs]] execution = "$EDITOR {directory}/{subpath}" invocation = "create {subpath}" + leave_broot = false [[verbs]] - execution = "less {file}" - invocation = "view" + execution = "git difftool -y {file}" + invocation = "git_diff" + leave_broot = false + shortcut = "gd" + + [[verbs]] + auto_exec = false + execution = "cp -r {file} {parent}/{file-stem}-{version}{file-dot-extension}" + invocation = "backup {version}" + key = "ctrl-b" + leave_broot = false + + [[verbs]] + execution = "$SHELL" + invocation = "terminal" + key = "ctrl-t" + leave_broot = false + set_working_dir = true [skin] ''