mirror of
https://github.com/nix-community/home-manager
synced 2024-12-24 02:39:48 +01:00
parent
e0c70942c0
commit
7413408b04
4 changed files with 98 additions and 3 deletions
|
@ -6,7 +6,7 @@ let
|
|||
cfg = config.programs.yazi;
|
||||
tomlFormat = pkgs.formats.toml { };
|
||||
|
||||
shellIntegration = ''
|
||||
bashIntegration = ''
|
||||
function ya() {
|
||||
tmp="$(mktemp -t "yazi-cwd.XXXXX")"
|
||||
yazi --cwd-file="$tmp"
|
||||
|
@ -16,6 +16,29 @@ let
|
|||
rm -f -- "$tmp"
|
||||
}
|
||||
'';
|
||||
|
||||
fishIntegration = ''
|
||||
function ya
|
||||
set tmp (mktemp -t "yazi-cwd.XXXXX")
|
||||
yazi --cwd-file="$tmp"
|
||||
if set cwd (cat -- "$tmp") && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]
|
||||
cd -- "$cwd"
|
||||
end
|
||||
rm -f -- "$tmp"
|
||||
end
|
||||
'';
|
||||
|
||||
nushellIntegration = ''
|
||||
def-env ya [] {
|
||||
let tmp = (mktemp -t "yazi-cwd.XXXXX")
|
||||
yazi --cwd-file $tmp
|
||||
let cwd = (cat -- $tmp)
|
||||
if $cwd != "" and $cwd != $env.PWD {
|
||||
cd $cwd
|
||||
}
|
||||
rm -f $tmp
|
||||
}
|
||||
'';
|
||||
in {
|
||||
meta.maintainers = [ maintainers.xyenon ];
|
||||
|
||||
|
@ -33,6 +56,10 @@ in {
|
|||
|
||||
enableZshIntegration = mkEnableOption "Zsh integration";
|
||||
|
||||
enableFishIntegration = mkEnableOption "Fish integration";
|
||||
|
||||
enableNushellIntegration = mkEnableOption "Nushell integration";
|
||||
|
||||
keymap = mkOption {
|
||||
type = tomlFormat.type;
|
||||
default = { };
|
||||
|
@ -113,9 +140,15 @@ in {
|
|||
config = mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
programs.bash.initExtra = mkIf cfg.enableBashIntegration shellIntegration;
|
||||
programs.bash.initExtra = mkIf cfg.enableBashIntegration bashIntegration;
|
||||
|
||||
programs.zsh.initExtra = mkIf cfg.enableZshIntegration shellIntegration;
|
||||
programs.zsh.initExtra = mkIf cfg.enableZshIntegration bashIntegration;
|
||||
|
||||
programs.fish.interactiveShellInit =
|
||||
mkIf cfg.enableFishIntegration fishIntegration;
|
||||
|
||||
programs.nushell.extraConfig =
|
||||
mkIf cfg.enableNushellIntegration nushellIntegration;
|
||||
|
||||
xdg.configFile = {
|
||||
"yazi/keymap.toml" = mkIf (cfg.keymap != { }) {
|
||||
|
|
|
@ -2,4 +2,6 @@
|
|||
yazi-settings = ./settings.nix;
|
||||
yazi-bash-integration-enabled = ./bash-integration-enabled.nix;
|
||||
yazi-zsh-integration-enabled = ./zsh-integration-enabled.nix;
|
||||
yazi-fish-integration-enabled = ./fish-integration-enabled.nix;
|
||||
yazi-nushell-integration-enabled = ./nushell-integration-enabled.nix;
|
||||
}
|
||||
|
|
27
tests/modules/programs/yazi/fish-integration-enabled.nix
Normal file
27
tests/modules/programs/yazi/fish-integration-enabled.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{ ... }:
|
||||
|
||||
let
|
||||
shellIntegration = ''
|
||||
function ya
|
||||
set tmp (mktemp -t "yazi-cwd.XXXXX")
|
||||
yazi --cwd-file="$tmp"
|
||||
if set cwd (cat -- "$tmp") && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]
|
||||
cd -- "$cwd"
|
||||
end
|
||||
rm -f -- "$tmp"
|
||||
end
|
||||
'';
|
||||
in {
|
||||
programs.fish.enable = true;
|
||||
|
||||
programs.yazi = {
|
||||
enable = true;
|
||||
enableFishIntegration = true;
|
||||
};
|
||||
|
||||
test.stubs.yazi = { };
|
||||
|
||||
nmt.script = ''
|
||||
assertFileContains home-files/.config/fish/config.fish '${shellIntegration}'
|
||||
'';
|
||||
}
|
33
tests/modules/programs/yazi/nushell-integration-enabled.nix
Normal file
33
tests/modules/programs/yazi/nushell-integration-enabled.nix
Normal file
|
@ -0,0 +1,33 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
let
|
||||
shellIntegration = ''
|
||||
def-env ya [] {
|
||||
let tmp = (mktemp -t "yazi-cwd.XXXXX")
|
||||
yazi --cwd-file $tmp
|
||||
let cwd = (cat -- $tmp)
|
||||
if $cwd != "" and $cwd != $env.PWD {
|
||||
cd $cwd
|
||||
}
|
||||
rm -f $tmp
|
||||
}
|
||||
'';
|
||||
in {
|
||||
programs.nushell.enable = true;
|
||||
|
||||
programs.yazi = {
|
||||
enable = true;
|
||||
enableNushellIntegration = true;
|
||||
};
|
||||
|
||||
test.stubs.yazi = { };
|
||||
|
||||
nmt.script = let
|
||||
configPath = if pkgs.stdenv.isDarwin then
|
||||
"home-files/Library/Application Support/nushell/config.nu"
|
||||
else
|
||||
"home-files/.config/nushell/config.nu";
|
||||
in ''
|
||||
assertFileContains '${configPath}' '${shellIntegration}'
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue