1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

broot: use upstream defaults, allow all config options (#2644)

* broot: use freeformType for config

* broot: use defaults from upstream

closes #2395

* broot: generate shell function

* broot: add @dermetfan to CODEOWNERS

* broot: rename `config` option to `settings`

* broot: make example more idiomatic

Co-authored-by: Nicolas Berbiche <nic.berbiche@gmail.com>

Co-authored-by: Nicolas Berbiche <nic.berbiche@gmail.com>
This commit is contained in:
Robin Stumm 2022-09-26 20:36:06 +02:00 committed by GitHub
parent 9e7394523e
commit 65b65ce5ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 186 additions and 223 deletions

2
.github/CODEOWNERS vendored
View file

@ -84,7 +84,7 @@ Makefile @thiagokokada
/modules/programs/bottom.nix @polykernel /modules/programs/bottom.nix @polykernel
/tests/modules/programs/bottom @polykernel /tests/modules/programs/bottom @polykernel
/modules/programs/broot.nix @aheaume /modules/programs/broot.nix @aheaume @dermetfan
/modules/programs/btop.nix @GaetanLepage /modules/programs/btop.nix @GaetanLepage
/tests/modules/programs/btop.nix @GaetanLepage /tests/modules/programs/btop.nix @GaetanLepage

View file

@ -8,7 +8,7 @@ The 21.05 release branch became the stable branch in May, 2021.
This release has the following notable changes: This release has the following notable changes:
* The <<opt-programs.broot.verbs>> 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 attribute set. To migrate, move the keys of the attrset into the list
items' `invocation` keys. For example, items' `invocation` keys. For example,
+ +

View file

@ -8,65 +8,15 @@ let
tomlFormat = pkgs.formats.toml { }; tomlFormat = pkgs.formats.toml { };
brootConf = { settingsModule = {
verbs = cfg.verbs; freeformType = tomlFormat.type;
skin = cfg.skin;
modal = cfg.modal;
};
in {
meta.maintainers = [ hm.maintainers.aheaume ];
options.programs.broot = {
enable = mkEnableOption "Broot, a better way to navigate directories";
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.
'';
};
options = {
modal = mkEnableOption "modal (vim) mode"; modal = mkEnableOption "modal (vim) mode";
verbs = mkOption { verbs = mkOption {
type = with types; listOf (attrsOf (either bool str)); type = with types; listOf (attrsOf (either bool str));
default = [ 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 '' example = literalExpression ''
[ [
{ invocation = "p"; execution = ":parent"; } { invocation = "p"; execution = ":parent"; }
@ -75,7 +25,7 @@ in {
{ invocation = "view"; execution = "less {file}"; } { invocation = "view"; execution = "less {file}"; }
{ {
invocation = "blop {name}\\.{type}"; invocation = "blop {name}\\.{type}";
execution = "/bin/mkdir {parent}/{type} && /usr/bin/nvim {parent}/{type}/{name}.{type}"; execution = "mkdir {parent}/{type} && ''${pkgs.neovim}/bin/nvim {parent}/{type}/{name}.{type}";
from_shell = true; from_shell = true;
} }
] ]
@ -121,13 +71,6 @@ in {
''; '';
}; };
package = mkOption {
type = types.package;
default = pkgs.broot;
defaultText = literalExpression "pkgs.broot";
description = "Package providing broot";
};
skin = mkOption { skin = mkOption {
type = types.attrsOf types.str; type = types.attrsOf types.str;
default = { }; default = { };
@ -184,93 +127,100 @@ in {
''; '';
}; };
}; };
};
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";
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.
'';
};
package = mkOption {
type = types.package;
default = pkgs.broot;
defaultText = literalExpression "pkgs.broot";
description = "Package providing broot";
};
settings = mkOption {
type = types.submodule settingsModule;
default = { };
description = "Verbatim config entries";
};
};
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
xdg.configFile."broot/conf.toml".source = 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 # Dummy file to prevent broot from trying to reinstall itself
xdg.configFile."broot/launcher/installed-v1".text = ""; xdg.configFile."broot/launcher/installed-v1".text = "";
programs.bash.initExtra = mkIf cfg.enableBashIntegration ( programs.broot.settings = builtins.fromJSON (builtins.readFile
# Using mkAfter to make it more likely to appear after other (pkgs.runCommand "default-conf.json" {
# manipulations of the prompt. nativeBuildInputs = [ pkgs.hjson ];
mkAfter '' } "hjson -c ${cfg.package.src}/resources/default-conf.hjson > $out"));
# 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.zsh.initExtra = mkIf cfg.enableZshIntegration '' programs.bash.initExtra = mkIf cfg.enableBashIntegration (shellInit "bash");
# 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.fish.shellInit = mkIf cfg.enableFishIntegration '' programs.zsh.initExtra = mkIf cfg.enableZshIntegration (shellInit "zsh");
# This script was automatically generated by the broot function
# More information can be found in https://github.com/Canop/broot programs.fish.shellInit = mkIf cfg.enableFishIntegration (shellInit "fish");
# 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
'';
}; };
} }

View file

@ -6,33 +6,46 @@ with lib;
config = { config = {
programs.broot = { programs.broot = {
enable = true; enable = true;
modal = true; settings.modal = true;
}; };
test.stubs.broot = { };
nmt.script = '' nmt.script = ''
assertFileExists home-files/.config/broot/conf.toml assertFileExists home-files/.config/broot/conf.toml
assertFileContent home-files/.config/broot/conf.toml ${ assertFileContent home-files/.config/broot/conf.toml ${
pkgs.writeText "broot.expected" '' pkgs.writeText "broot.expected" ''
modal = true modal = true
show_selection_mark = true
[[verbs]] [[verbs]]
execution = ":parent" execution = "$EDITOR +{line} {file}"
invocation = "p"
[[verbs]]
execution = "$EDITOR {file}"
invocation = "edit" invocation = "edit"
leave_broot = false
shortcut = "e" shortcut = "e"
[[verbs]] [[verbs]]
execution = "$EDITOR {directory}/{subpath}" execution = "$EDITOR {directory}/{subpath}"
invocation = "create {subpath}" invocation = "create {subpath}"
leave_broot = false
[[verbs]] [[verbs]]
execution = "less {file}" execution = "git difftool -y {file}"
invocation = "view" 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] [skin]
'' ''