Files
nixos/apps/yazi/default.nix
T

55 lines
1.4 KiB
Nix

{
pkgs,
config,
...
}: let
yazi-picker = pkgs.writeShellScriptBin "yazi-picker" ''
path="$1"
[ -z "$path" ] && path="."
if [ "$2" = "true" ]; then
# Save file mode
# In save mode, we might want to just open the directory,
# but yazi --chooser-file works for picking a file to overwrite or a directory.
# For a "Save As" flow where you type a name, standard yazi chooser might be limited
# without custom lua, but selecting a directory works.
# For now, treat same as open.
:
fi
out="$HOME/.cache/yazi-chooser"
rm -f "$out"
# We need to block until ghostty closes, or use --wait if available/default behavior.
# Ghostty -e does not automatically detach, so it should block.
${pkgs.ghostty}/bin/ghostty --class="yazi-picker" --title="File Picker" -e ${pkgs.yazi}/bin/yazi "$path" --chooser-file="$out"
if [ -f "$out" ]; then
cat "$out"
rm "$out"
fi
'';
in {
programs.yazi = {
enable = true;
enableFishIntegration = true;
settings = {
manager = {
show_hidden = true;
sort_by = "natural";
sort_dir_first = true;
linemode = "size";
};
};
};
home.packages = [
yazi-picker
];
xdg.configFile."xdg-desktop-portal-termfilechooser/config".text = ''
[filechooser]
cmd=${yazi-picker}/bin/yazi-picker
'';
}