2019-03-27 11:36:37 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.broot;
|
|
|
|
|
2021-03-13 04:20:00 +00:00
|
|
|
tomlFormat = pkgs.formats.toml { };
|
2019-03-27 11:36:37 +00:00
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
settingsModule = {
|
|
|
|
freeformType = tomlFormat.type;
|
|
|
|
|
|
|
|
options = {
|
2023-07-01 23:45:18 +00:00
|
|
|
modal = mkEnableOption "modal (vim) mode";
|
2022-09-26 18:36:06 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2022-09-26 18:36:06 +00:00
|
|
|
Define new verbs. For more information, see
|
2023-07-01 00:40:42 +00:00
|
|
|
[Verb Definition Attributes](https://dystroy.org/broot/documentation/configuration/#verb-definition-attributes)
|
|
|
|
in the broot documentation.
|
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
The possible attributes are:
|
2023-07-01 00:40:42 +00:00
|
|
|
|
|
|
|
`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)</term>
|
|
|
|
: whether the verb must be executed from the
|
|
|
|
parent shell (default: `false`)
|
2022-09-26 18:36:06 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2022-09-26 18:36:06 +00:00
|
|
|
Color configuration.
|
2023-07-01 00:40:42 +00:00
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
Complete list of keys (expected to change before the v1 of broot):
|
|
|
|
|
2023-07-01 00:40:42 +00:00
|
|
|
* `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 color.
|
2022-09-26 18:36:06 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2019-03-27 11:36:37 +00:00
|
|
|
};
|
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
'';
|
2020-02-01 23:39:17 +00:00
|
|
|
in {
|
2023-05-14 10:40:31 +00:00
|
|
|
meta.maintainers = [ hm.maintainers.aheaume maintainers.dermetfan ];
|
2019-03-27 11:36:37 +00:00
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
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"
|
|
|
|
])
|
|
|
|
];
|
|
|
|
|
2019-03-27 11:36:37 +00:00
|
|
|
options.programs.broot = {
|
2023-07-01 23:45:18 +00:00
|
|
|
enable = mkEnableOption "Broot, a better way to navigate directories";
|
2019-03-27 11:36:37 +00:00
|
|
|
|
|
|
|
enableBashIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-03-27 11:36:37 +00:00
|
|
|
Whether to enable Bash integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableZshIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-03-27 11:36:37 +00:00
|
|
|
Whether to enable Zsh integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableFishIntegration = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2019-03-27 11:36:37 +00:00
|
|
|
Whether to enable Fish integration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-01-06 03:16:36 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.broot;
|
2021-10-09 09:14:08 +00:00
|
|
|
defaultText = literalExpression "pkgs.broot";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Package providing broot";
|
2021-01-06 03:16:36 +00:00
|
|
|
};
|
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = types.submodule settingsModule;
|
2020-02-01 23:39:17 +00:00
|
|
|
default = { };
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Verbatim config entries";
|
2019-03-27 11:36:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-01-06 03:16:36 +00:00
|
|
|
home.packages = [ cfg.package ];
|
2019-03-27 11:36:37 +00:00
|
|
|
|
2022-09-27 10:19:02 +00:00
|
|
|
xdg.configFile."broot" = {
|
|
|
|
recursive = true;
|
|
|
|
source = pkgs.symlinkJoin {
|
|
|
|
name = "xdg.configFile.broot";
|
|
|
|
paths = [
|
|
|
|
# Copy all files under /resources/default-conf
|
|
|
|
"${cfg.package.src}/resources/default-conf"
|
|
|
|
|
|
|
|
# Dummy file to prevent broot from trying to reinstall itself
|
|
|
|
(pkgs.writeTextDir "launcher/installed-v1" "")
|
|
|
|
];
|
|
|
|
|
|
|
|
postBuild = ''
|
2023-03-05 12:08:09 +00:00
|
|
|
ln -s ${
|
|
|
|
tomlFormat.generate "broot-config" cfg.settings
|
|
|
|
} $out/conf.toml
|
|
|
|
|
|
|
|
# Remove conf.hjson, whose content has been merged into programs.broot.settings
|
2022-09-27 10:19:02 +00:00
|
|
|
rm $out/conf.hjson
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2019-03-27 11:36:37 +00:00
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
programs.broot.settings = builtins.fromJSON (builtins.readFile
|
|
|
|
(pkgs.runCommand "default-conf.json" {
|
|
|
|
nativeBuildInputs = [ pkgs.hjson ];
|
2022-09-27 10:19:02 +00:00
|
|
|
}
|
|
|
|
"hjson -c ${cfg.package.src}/resources/default-conf/conf.hjson > $out"));
|
2019-03-27 11:36:37 +00:00
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
programs.bash.initExtra = mkIf cfg.enableBashIntegration (shellInit "bash");
|
2019-03-27 11:36:37 +00:00
|
|
|
|
2022-09-26 18:36:06 +00:00
|
|
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration (shellInit "zsh");
|
|
|
|
|
|
|
|
programs.fish.shellInit = mkIf cfg.enableFishIntegration (shellInit "fish");
|
2019-03-27 11:36:37 +00:00
|
|
|
};
|
|
|
|
}
|