Yazi: Difference between revisions

From NixOS Wiki
Layer-09 (talk | contribs)
m Removed numbering
Layer-09 (talk | contribs)
Yazi has changed some of its syntax, which broke the advanced configuration.
Line 1: Line 1:
[https://yazi-rs.github.io/ 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'''<ref>https://yazi-rs.github.io/</ref> is a '''blazing-fast''' terminal file manager developed in '''Rust''', using '''non-blocking async I/O''' for an efficient, user-friendly, and highly customizable experience. It features '''full asynchronous support''', distributing CPU tasks across multiple threads to maximize resource use and improve '''performance'''.


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.
It offers powerful '''async task scheduling''' with real-time progress updates, task cancellation, and internal prioritization. It supports multiple image protocols natively and integrates with '''Überzug++''' for broad terminal compatibility. Additionally, Yazi includes built-in '''code highlighting''' and '''image decoding''' functionalities, along with a '''pre-loading''' mechanism to speed up file loading processes.


== Installation ==
== Installation ==
Line 10: Line 10:
</syntaxhighlight>
</syntaxhighlight>


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


==== User-Specific Installation with Home Manager ====
==== Using home configuration ====
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
home.packages = [  
home.packages = [  
Line 38: Line 38:


==== Advanced ====
==== Advanced ====
The configuration below is using home manager, but the same can be achieved if system-wide.<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
programs.yazi = {
programs.yazi = {
   enable = true;
   enable = true;
   settings = {
   settings = {
     manager = {
     manager = {
      layout = [
        1
        4
        3
      ];
       sort_by = "natural";
       sort_by = "natural";
      sort_sensitive = true;
      sort_reverse = false;
      sort_dir_first = true;
      linemode = "none";
       show_hidden = true;
       show_hidden = true;
       show_symlink = true;
       show_symlink = true;
Line 50: Line 59:
     preview = {
     preview = {
       image_filter = "lanczos3";
       image_filter = "lanczos3";
       image_quality = 80;
       image_quality = 90;
      tab_size = 1;
       max_width = 600;
       max_width = 600;
       max_height = 900;
       max_height = 900;
      cache_dir = "";
       ueberzug_scale = 1;
       ueberzug_scale = 1;
       ueberzug_offset = [0 0 0 0];
       ueberzug_offset = [
        0
        0
        0
        0
      ];
     };
     };


Line 62: Line 78:
       bizarre_retry = 5;
       bizarre_retry = 5;
     };
     };
  };
}


  open = {
</syntaxhighlight>
      rules = [
 
        {
== Tips and Tricks ==
          use = "open";
 
          mime = "image/*";
==== Location 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].
        {
          use = ["play" "reveal"];
          mime = "video/*";
        }
        {
          use = ["play" "reveal"];
          mime = "audio/*";
        }
      ];
    };


    opener = {
The system-wide options are listed on [https://mynixos.com/search?q=yazi MyNixOS].
      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 = {
==== Bleeding edge ====
    manager.keymap = [
The upstream repository provides a flake so that Nix users can easily keep up with the bleeding edge.<ref>https://yazi-rs.github.io/docs/installation/#nix-flakes</ref><syntaxhighlight lang="nix">
      {
inputs = {
        exec = "shell 'dragon -x -i -T \"$1\"' --confirm";
    yazi.url = "github:sxyazi/yazi";
        on = ["<C-d>"];
};
      }
</syntaxhighlight>Afterwords, you can use the new package.<syntaxhighlight lang="nix">
      {
# Global
        exec = "arrow -1";
environment.systemPackages = [ yazi.packages.${pkgs.system}.default ];
        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 = [
# Home Manager
      {
home.packages = [ yazi.packages.${pkgs.system}.default ];            
        exec = "close";
</syntaxhighlight>Pre-built artifacts are served at https://yazi.cachix.org, so that Nix users don't have to build Yazi on their machine.<ref>https://yazi-rs.github.io/docs/installation/#cache</ref><syntaxhighlight lang="nix">
        on = ["<Esc>"];
nix = {
      }
  settings = {
      {
    substitute = true;
        exec = "arrow -1";
    substituters = [
        on = ["<Up>"];
       "https://yazi.cachix.org"
      }
    ];
    select.keymap = [
      {
        exec = "close";
        on = ["<Esc>"];
      }
      {
        exec = "close --submit";
        on = ["<Enter>"];
      }
    ];
    input.keymap = [
      {
        exec = "close";
        on = ["<Esc>"];
      }
       {
        exec = "close --submit";
        on = ["<Enter>"];
      }
     ];
     ];
     help.keymap = [
     trusted-public-keys = [
       {
       "yazi.cachix.org-1:Dcdz63NZKfvUCbDGngQDAZq6kOroIrFoyO064uvLh8k="
        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";
        }
      ];
    };
   };
   };
};
};
</syntaxhighlight>
</syntaxhighlight>


== Tips and Tricks ==
==== Stylix integration ====
 
<syntaxhighlight lang="nix">
==== 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 system-wide options are listed on [https://mynixos.com/search?q=yazi MyNixOS].
 
==== Can this be used with stylix? ====
Yes, it can. See the following configuration:<syntaxhighlight lang="nix">
theme = with config.stylix.base16Scheme; {
theme = with config.stylix.base16Scheme; {
   filetype = {
   filetype = {
Line 254: Line 139:
   };
   };
};
};
</syntaxhighlight>Stylix can also do it automatically for you. You have to set:<syntaxhighlight lang="nix">
</syntaxhighlight>Stylix can do it automatically for you if the following option is set:<syntaxhighlight lang="nix">
stylix.targets.yazi.enable = true;
stylix.targets.yazi.enable = true;
</syntaxhighlight>
</syntaxhighlight>


==== How to map yazi to a key? ====
==== Key mapping ====
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">
<syntaxhighlight lang="nix">
# Hyprland
bind = [
bind = [
   "$mod, E, exec, kitty -e yazi"
   "$mod, E, exec, kitty -e yazi"
Line 268: Line 154:


== References ==
== References ==
# https://github.com/sxyazi/yazi
# https://yazi-rs.github.io/
# https://mynixos.com/search?q=yazi
# https://nix-community.github.io/home-manager/options.xhtml#opt-programs.yazi.enable
# https://stylix.danth.me/options/hm.html#stylixtargetsyazienable
[[Category:Applications]]
[[Category:Applications]]
[[Category:File Manager]]
[[Category:File Manager]]

Revision as of 10:32, 7 September 2024

Yazi[1] is a blazing-fast terminal file manager developed in Rust, using non-blocking async I/O for an efficient, user-friendly, and highly customizable experience. It features full asynchronous support, distributing CPU tasks across multiple threads to maximize resource use and improve performance.

It offers powerful async task scheduling with real-time progress updates, task cancellation, and internal prioritization. It supports multiple image protocols natively and integrates with Überzug++ for broad terminal compatibility. Additionally, Yazi includes built-in code highlighting and image decoding functionalities, along with a pre-loading mechanism to speed up file loading processes.

Installation

Using nix-shell

nix-shell -p yazi

Using global configuration

environment.systemPackages = [
  pkgs.yazi
];

After modifying your configuration, apply the changes by running:

sudo nixos-rebuild switch

Using home configuration

home.packages = [ 
  pkgs.yazi 
];

After updating your configuration, apply the changes by running:

home-manager switch

Configuration

Basic

programs.yazi = {
    enable = true;
};

Advanced

programs.yazi = {
  enable = true;
  settings = {
    manager = {
      layout = [
        1
        4
        3
      ];
      sort_by = "natural";
      sort_sensitive = true;
      sort_reverse = false;
      sort_dir_first = true;
      linemode = "none";
      show_hidden = true;
      show_symlink = true;
    };

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

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

Tips and Tricks

Location of options

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

The system-wide options are listed on MyNixOS.

Bleeding edge

The upstream repository provides a flake so that Nix users can easily keep up with the bleeding edge.[2]

inputs = {
    yazi.url = "github:sxyazi/yazi";
};

Afterwords, you can use the new package.

# Global
environment.systemPackages = [ yazi.packages.${pkgs.system}.default ];

# Home Manager
home.packages = [ yazi.packages.${pkgs.system}.default ];

Pre-built artifacts are served at https://yazi.cachix.org, so that Nix users don't have to build Yazi on their machine.[3]

nix = {
  settings = {
    substitute = true;
    substituters = [
      "https://yazi.cachix.org"
    ];
    trusted-public-keys = [
      "yazi.cachix.org-1:Dcdz63NZKfvUCbDGngQDAZq6kOroIrFoyO064uvLh8k="
    ];
  };
};

Stylix integration

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

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

Stylix can do it automatically for you if the following option is set:

stylix.targets.yazi.enable = true;

Key mapping

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

Troubleshooting

References