Yazi: Difference between revisions

From NixOS Wiki
Klinger (talk | contribs)
m link added
Layer-09 (talk | contribs)
m Removed numbering
Line 5: Line 5:
== Installation ==
== Installation ==


==== 2.1 Using nix-shell ====
==== Using nix-shell ====
<syntaxhighlight lang="bash" start="3">
<syntaxhighlight lang="bash" start="3">
nix-shell -p yazi
nix-shell -p yazi
</syntaxhighlight>
</syntaxhighlight>


==== 2.2 System-Wide Installation on NixOS ====
==== System-Wide Installation on NixOS ====
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
environment.systemPackages = [
environment.systemPackages = [
Line 19: Line 19:
</syntaxhighlight>
</syntaxhighlight>


==== 2.3 User-Specific Installation with Home Manager ====
==== User-Specific Installation with Home Manager ====
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
home.packages = [  
home.packages = [  
Line 30: Line 30:
== Configuration ==
== Configuration ==


==== 3.1 Basic ====
==== Basic ====
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.yazi = {
programs.yazi = {
Line 37: Line 37:
</syntaxhighlight>
</syntaxhighlight>


==== 3.2 Advanced ====
==== Advanced ====
The configuration below is using home manager, but the same can be achieved if system-wide.<syntaxhighlight lang="nix">
The configuration below is using home manager, but the same can be achieved if system-wide.<syntaxhighlight lang="nix">
programs.yazi = {
programs.yazi = {
Line 225: Line 225:
== Tips and Tricks ==
== Tips and Tricks ==


==== 4.1 Where to see a list of options? ====
==== Where to see a list of options? ====
The home manager options are defined in the following [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.yazi.enable Home Manager Options Manual].
The home manager options are defined in the following [https://nix-community.github.io/home-manager/options.xhtml#opt-programs.yazi.enable Home Manager Options Manual].


The system-wide options are listed on [https://mynixos.com/search?q=yazi MyNixOS].
The system-wide options are listed on [https://mynixos.com/search?q=yazi MyNixOS].


==== 4.2 Can this be used with stylix? ====
==== Can this be used with stylix? ====
Yes, it can. See the following configuration:<syntaxhighlight lang="nix">
Yes, it can. See the following configuration:<syntaxhighlight lang="nix">
theme = with config.stylix.base16Scheme; {
theme = with config.stylix.base16Scheme; {
Line 258: Line 258:
</syntaxhighlight>
</syntaxhighlight>


==== 4.3 How to map yazi to a key? ====
==== How to map yazi to a key? ====
It depends on the window manager that you are using. On [https://wiki.nixos.org/wiki/Hyprland Hyprland] it's fairly easy:<syntaxhighlight lang="nix">
It depends on the window manager that you are using. On [https://wiki.nixos.org/wiki/Hyprland Hyprland] it's fairly easy:<syntaxhighlight lang="nix">
bind = [
bind = [

Revision as of 06:36, 24 June 2024

Yazi is a blazing-fast terminal file manager developed in Rust, leveraging non-blocking async I/O to offer an efficient, user-friendly, and highly customizable file management experience. It stands out for its full asynchronous support, where all I/O operations are asynchronous, and CPU tasks are distributed across multiple threads, maximizing resource utilization. This design choice significantly enhances performance and responsiveness.

Yazi introduces powerful async task scheduling and management capabilities, providing real-time progress updates, task cancellation, and internal task prioritization. It supports multiple image protocols natively and integrates with Überzug++ for extensive terminal compatibility. Additionally, Yazi includes built-in code highlighting and image decoding functionalities, combined with a pre-loading mechanism that speeds up both image and regular file loading processes.

Installation

Using nix-shell

nix-shell -p yazi

System-Wide Installation on NixOS

environment.systemPackages = [
  pkgs.yazi
];

After modifying your configuration, apply the changes by running:

sudo nixos-rebuild switch

User-Specific Installation with Home Manager

home.packages = [ 
  pkgs.yazi 
];

After updating your configuration, apply the changes by running:

home-manager switch

Configuration

Basic

programs.yazi = {
    enable = true;
};

Advanced

The configuration below is using home manager, but the same can be achieved if system-wide.

programs.yazi = {
  enable = true;
  settings = {
    manager = {
      sort_by = "natural";
      show_hidden = true;
      show_symlink = true;
    };

    preview = {
      image_filter = "lanczos3";
      image_quality = 80;
      max_width = 600;
      max_height = 900;
      ueberzug_scale = 1;
      ueberzug_offset = [0 0 0 0];
    };

    tasks = {
      micro_workers = 5;
      macro_workers = 10;
      bizarre_retry = 5;
    };

  open = {
      rules = [
        {
          use = "open";
          mime = "image/*";
        }
        {
          use = ["play" "reveal"];
          mime = "video/*";
        }
        {
          use = ["play" "reveal"];
          mime = "audio/*";
        }
      ];
    };

    opener = {
      edit = [
        {
          exec = "nvim \"$@\"";
          block = true;
          for = "unix";
        }
      ];
      open = [
        {
          exec = "qimgv \"$@\"";
          desc = "Open";
        }
      ];
      reveal = [
        {
          exec = "''${pkgs.exiftool}/bin/exiftool \"$1\"; echo \"Press enter to exit\"; read _''";
          block = true;
          desc = "Show EXIF";
        }
      ];
      play = [
        {
          exec = "mpv \"$@\"";
          orphan = true;
        }
        {
          exec = "''${pkgs.mediainfo}/bin/mediainfo \"$1\"; echo \"Press enter to exit\"; read _''";
          block = true;
          desc = "Show media info";
        }
      ];
      archive = [
        {
          exec = "unar \"$1\"";
          desc = "Extract here";
        }
      ];
    };
  };

  keymap = {
    manager.keymap = [
      {
        exec = "shell 'dragon -x -i -T \"$1\"' --confirm";
        on = ["<C-d>"];
      }
      {
        exec = "arrow -1";
        desc = "Move cursor up";
        on = ["<Up>"];
      }
    ];
    completion.keymap = [
      {
        on = ["<Esc>"];
        run = "close";
        desc = "Cancel completion";
      }
      {
        on = ["<Tab>"];
        run = "close --submit";
        desc = "Submit the completion";
      }
    ];

    tasks.keymap = [
      {
        exec = "close";
        on = ["<Esc>"];
      }
      {
        exec = "arrow -1";
        on = ["<Up>"];
      }
    ];
    select.keymap = [
      {
        exec = "close";
        on = ["<Esc>"];
      }
      {
        exec = "close --submit";
        on = ["<Enter>"];
      }
    ];
    input.keymap = [
      {
        exec = "close";
        on = ["<Esc>"];
      }
      {
        exec = "close --submit";
        on = ["<Enter>"];
      }
    ];
    help.keymap = [
      {
        exec = "escape";
        on = ["<Esc>"];
      }
      {
        exec = "filter";
        on = ["/"];
      }
    ];
  };
  theme = {
    manager = {
      border_symbol = " ";
    };
    icon = {
      rules = [
        {
          name = "*.jsx";
          text = "";
          fg = "#20c2e3";
        }
        {
          name = "*.lua";
          text = "";
          fg = "#51a0cf";
        }
        {
          name = "*.nix";
          text = "";
          fg = "#7ebae4";
        }
      ];
    };
    filetype = {
      rules = [
        # Images
        {
          mime = "image/*";
          fg = "#7ebae4";
        }
      ];
    };
  };
};

Tips and Tricks

Where to see a list of options?

The home manager options are defined in the following Home Manager Options Manual.

The system-wide options are listed on MyNixOS.

Can this be used with stylix?

Yes, it can. See the following configuration:

theme = with config.stylix.base16Scheme; {
  filetype = {
    rules = [
      # Images
      {
        mime = "image/*";
        fg = "#${base0B}";
      }

      # Videos
      {
        mime = "video/*";
        fg = "#${base03}";
      }
      # Audio
      {
        mime = "audio/*";
        fg = "#${base08}";
      }
    ];
  };
};

Stylix can also do it automatically for you. You have to set:

stylix.targets.yazi.enable = true;

How to map yazi to a key?

It depends on the window manager that you are using. On Hyprland it's fairly easy:

bind = [
  "$mod, E, exec, kitty -e yazi"
];

Troubleshooting

References

  1. https://github.com/sxyazi/yazi
  2. https://yazi-rs.github.io/
  3. https://mynixos.com/search?q=yazi
  4. https://nix-community.github.io/home-manager/options.xhtml#opt-programs.yazi.enable
  5. https://stylix.danth.me/options/hm.html#stylixtargetsyazienable