yazi: add fish and nushell integration

PR #4493
This commit is contained in:
XYenon 2023-09-22 19:00:16 +08:00 committed by Robert Helgesson
parent e0c70942c0
commit 7413408b04
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
4 changed files with 98 additions and 3 deletions

View File

@ -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 != { }) {

View File

@ -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;
}

View 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}'
'';
}

View 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}'
'';
}