mirror of
https://github.com/nix-community/home-manager
synced 2024-11-20 01:59:45 +01:00
programs.yazi: add module (#4373)
add module for yazi https://github.com/sxyazi/yazi a terminal rust file browser akin to ranger or joshuto
This commit is contained in:
parent
f8c5fd7509
commit
90e62f96c7
11 changed files with 334 additions and 0 deletions
|
@ -1200,6 +1200,13 @@ in
|
|||
A new module is available: 'programs.qcal'.
|
||||
'';
|
||||
}
|
||||
|
||||
{
|
||||
time = "2023-08-23T12:01:06+00:00";
|
||||
message = ''
|
||||
A new module is available: 'programs.yazi'.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -221,6 +221,7 @@ let
|
|||
./programs/wlogout.nix
|
||||
./programs/wofi.nix
|
||||
./programs/xmobar.nix
|
||||
./programs/yazi.nix
|
||||
./programs/yt-dlp.nix
|
||||
./programs/z-lua.nix
|
||||
./programs/zathura.nix
|
||||
|
|
132
modules/programs/yazi.nix
Normal file
132
modules/programs/yazi.nix
Normal file
|
@ -0,0 +1,132 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.programs.yazi;
|
||||
tomlFormat = pkgs.formats.toml { };
|
||||
|
||||
shellIntegration = ''
|
||||
function ya() {
|
||||
tmp="$(mktemp -t "yazi-cwd.XXXXX")"
|
||||
yazi --cwd-file="$tmp"
|
||||
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
|
||||
cd -- "$cwd"
|
||||
fi
|
||||
rm -f -- "$tmp"
|
||||
}
|
||||
'';
|
||||
in {
|
||||
meta.maintainers = [ maintainers.xyenon ];
|
||||
|
||||
options.programs.yazi = {
|
||||
enable = mkEnableOption "yazi";
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
default = pkgs.yazi;
|
||||
defaultText = literalExpression "pkgs.yazi";
|
||||
description = "Yazi package to install.";
|
||||
};
|
||||
|
||||
enableBashIntegration = mkEnableOption "Bash integration";
|
||||
|
||||
enableZshIntegration = mkEnableOption "Zsh integration";
|
||||
|
||||
keymap = mkOption {
|
||||
type = tomlFormat.type;
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
input.keymap = [
|
||||
{ exec = "close"; on = [ "<C-q>" ]; }
|
||||
{ exec = "close --submit"; on = [ "<Enter>" ]; }
|
||||
{ exec = "escape"; on = [ "<Esc>" ]; }
|
||||
{ exec = "backspace"; on = [ "<Backspace>" ]; }
|
||||
];
|
||||
manager.keymap = [
|
||||
{ exec = "escape"; on = [ "<Esc>" ]; }
|
||||
{ exec = "quit"; on = [ "q" ]; }
|
||||
{ exec = "close"; on = [ "<C-q>" ]; }
|
||||
];
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Configuration written to
|
||||
{file}`$XDG_CONFIG_HOME/yazi/keymap.toml`.
|
||||
|
||||
See <https://github.com/sxyazi/yazi/blob/main/config/docs/keymap.md>
|
||||
for the full list of options.
|
||||
'';
|
||||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = tomlFormat.type;
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
log = {
|
||||
enabled = false;
|
||||
};
|
||||
manager = {
|
||||
show_hidden = false;
|
||||
sort_by = "modified";
|
||||
sort_dir_first = true;
|
||||
sort_reverse = true;
|
||||
};
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Configuration written to
|
||||
{file}`$XDG_CONFIG_HOME/yazi/yazi.toml`.
|
||||
|
||||
See <https://github.com/sxyazi/yazi/blob/main/config/docs/yazi.md>
|
||||
for the full list of options.
|
||||
'';
|
||||
};
|
||||
|
||||
theme = mkOption {
|
||||
type = tomlFormat.type;
|
||||
default = { };
|
||||
example = literalExpression ''
|
||||
{
|
||||
filetype = {
|
||||
rules = [
|
||||
{ fg = "#7AD9E5"; mime = "image/*"; }
|
||||
{ fg = "#F3D398"; mime = "video/*"; }
|
||||
{ fg = "#F3D398"; mime = "audio/*"; }
|
||||
{ fg = "#CD9EFC"; mime = "application/x-bzip"; }
|
||||
];
|
||||
};
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Configuration written to
|
||||
{file}`$XDG_CONFIG_HOME/yazi/theme.toml`.
|
||||
|
||||
See <https://github.com/sxyazi/yazi/blob/main/config/docs/theme.md>
|
||||
for the full list of options
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
programs.bash.initExtra = mkIf cfg.enableBashIntegration shellIntegration;
|
||||
|
||||
programs.zsh.initExtra = mkIf cfg.enableZshIntegration shellIntegration;
|
||||
|
||||
xdg.configFile = {
|
||||
"yazi/keymap.toml" = mkIf (cfg.keymap != { }) {
|
||||
source = tomlFormat.generate "yazi-keymap" cfg.keymap;
|
||||
};
|
||||
"yazi/yazi.toml" = mkIf (cfg.settings != { }) {
|
||||
source = tomlFormat.generate "yazi-settings" cfg.settings;
|
||||
};
|
||||
"yazi/theme.toml" = mkIf (cfg.theme != { }) {
|
||||
source = tomlFormat.generate "yazi-theme" cfg.theme;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -143,6 +143,7 @@ import nmt {
|
|||
./modules/programs/vscode
|
||||
./modules/programs/watson
|
||||
./modules/programs/wezterm
|
||||
./modules/programs/yazi
|
||||
./modules/programs/zellij
|
||||
./modules/programs/zplug
|
||||
./modules/programs/zsh
|
||||
|
|
27
tests/modules/programs/yazi/bash-integration-enabled.nix
Normal file
27
tests/modules/programs/yazi/bash-integration-enabled.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{ ... }:
|
||||
|
||||
let
|
||||
shellIntegration = ''
|
||||
function ya() {
|
||||
tmp="$(mktemp -t "yazi-cwd.XXXXX")"
|
||||
yazi --cwd-file="$tmp"
|
||||
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
|
||||
cd -- "$cwd"
|
||||
fi
|
||||
rm -f -- "$tmp"
|
||||
}
|
||||
'';
|
||||
in {
|
||||
programs.bash.enable = true;
|
||||
|
||||
programs.yazi = {
|
||||
enable = true;
|
||||
enableBashIntegration = true;
|
||||
};
|
||||
|
||||
test.stubs.yazi = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContains home-files/.bashrc '${shellIntegration}'
|
||||
'';
|
||||
}
|
5
tests/modules/programs/yazi/default.nix
Normal file
5
tests/modules/programs/yazi/default.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
yazi-settings = ./settings.nix;
|
||||
yazi-bash-integration-enabled = ./bash-integration-enabled.nix;
|
||||
yazi-zsh-integration-enabled = ./zsh-integration-enabled.nix;
|
||||
}
|
27
tests/modules/programs/yazi/keymap-expected.toml
Normal file
27
tests/modules/programs/yazi/keymap-expected.toml
Normal file
|
@ -0,0 +1,27 @@
|
|||
[[input.keymap]]
|
||||
exec = "close"
|
||||
on = ["<C-q>"]
|
||||
|
||||
[[input.keymap]]
|
||||
exec = "close --submit"
|
||||
on = ["<Enter>"]
|
||||
|
||||
[[input.keymap]]
|
||||
exec = "escape"
|
||||
on = ["<Esc>"]
|
||||
|
||||
[[input.keymap]]
|
||||
exec = "backspace"
|
||||
on = ["<Backspace>"]
|
||||
|
||||
[[manager.keymap]]
|
||||
exec = "escape"
|
||||
on = ["<Esc>"]
|
||||
|
||||
[[manager.keymap]]
|
||||
exec = "quit"
|
||||
on = ["q"]
|
||||
|
||||
[[manager.keymap]]
|
||||
exec = "close"
|
||||
on = ["<C-q>"]
|
8
tests/modules/programs/yazi/settings-expected.toml
Normal file
8
tests/modules/programs/yazi/settings-expected.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[log]
|
||||
enabled = false
|
||||
|
||||
[manager]
|
||||
show_hidden = false
|
||||
sort_by = "modified"
|
||||
sort_dir_first = true
|
||||
sort_reverse = true
|
84
tests/modules/programs/yazi/settings.nix
Normal file
84
tests/modules/programs/yazi/settings.nix
Normal file
|
@ -0,0 +1,84 @@
|
|||
{ ... }:
|
||||
|
||||
{
|
||||
programs.yazi = {
|
||||
enable = true;
|
||||
|
||||
keymap = {
|
||||
input.keymap = [
|
||||
{
|
||||
exec = "close";
|
||||
on = [ "<C-q>" ];
|
||||
}
|
||||
{
|
||||
exec = "close --submit";
|
||||
on = [ "<Enter>" ];
|
||||
}
|
||||
{
|
||||
exec = "escape";
|
||||
on = [ "<Esc>" ];
|
||||
}
|
||||
{
|
||||
exec = "backspace";
|
||||
on = [ "<Backspace>" ];
|
||||
}
|
||||
];
|
||||
manager.keymap = [
|
||||
{
|
||||
exec = "escape";
|
||||
on = [ "<Esc>" ];
|
||||
}
|
||||
{
|
||||
exec = "quit";
|
||||
on = [ "q" ];
|
||||
}
|
||||
{
|
||||
exec = "close";
|
||||
on = [ "<C-q>" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
settings = {
|
||||
log = { enabled = false; };
|
||||
manager = {
|
||||
show_hidden = false;
|
||||
sort_by = "modified";
|
||||
sort_dir_first = true;
|
||||
sort_reverse = true;
|
||||
};
|
||||
};
|
||||
theme = {
|
||||
filetype = {
|
||||
rules = [
|
||||
{
|
||||
fg = "#7AD9E5";
|
||||
mime = "image/*";
|
||||
}
|
||||
{
|
||||
fg = "#F3D398";
|
||||
mime = "video/*";
|
||||
}
|
||||
{
|
||||
fg = "#F3D398";
|
||||
mime = "audio/*";
|
||||
}
|
||||
{
|
||||
fg = "#CD9EFC";
|
||||
mime = "application/x-bzip";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test.stubs.yazi = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContent home-files/.config/yazi/keymap.toml \
|
||||
${./keymap-expected.toml}
|
||||
assertFileContent home-files/.config/yazi/yazi.toml \
|
||||
${./settings-expected.toml}
|
||||
assertFileContent home-files/.config/yazi/theme.toml \
|
||||
${./theme-expected.toml}
|
||||
'';
|
||||
}
|
15
tests/modules/programs/yazi/theme-expected.toml
Normal file
15
tests/modules/programs/yazi/theme-expected.toml
Normal file
|
@ -0,0 +1,15 @@
|
|||
[[filetype.rules]]
|
||||
fg = "#7AD9E5"
|
||||
mime = "image/*"
|
||||
|
||||
[[filetype.rules]]
|
||||
fg = "#F3D398"
|
||||
mime = "video/*"
|
||||
|
||||
[[filetype.rules]]
|
||||
fg = "#F3D398"
|
||||
mime = "audio/*"
|
||||
|
||||
[[filetype.rules]]
|
||||
fg = "#CD9EFC"
|
||||
mime = "application/x-bzip"
|
27
tests/modules/programs/yazi/zsh-integration-enabled.nix
Normal file
27
tests/modules/programs/yazi/zsh-integration-enabled.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{ ... }:
|
||||
|
||||
let
|
||||
shellIntegration = ''
|
||||
function ya() {
|
||||
tmp="$(mktemp -t "yazi-cwd.XXXXX")"
|
||||
yazi --cwd-file="$tmp"
|
||||
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
|
||||
cd -- "$cwd"
|
||||
fi
|
||||
rm -f -- "$tmp"
|
||||
}
|
||||
'';
|
||||
in {
|
||||
programs.zsh.enable = true;
|
||||
|
||||
programs.yazi = {
|
||||
enable = true;
|
||||
enableBashIntegration = true;
|
||||
};
|
||||
|
||||
test.stubs.yazi = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContains home-files/.zshrc '${shellIntegration}'
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue