Yazi: Improve openers.

This commit is contained in:
Dmitry Voronin 2024-10-17 22:38:47 +03:00
parent 3f4f48fa8b
commit 2dc3829b5c
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
6 changed files with 49 additions and 17 deletions

View file

@ -9,8 +9,8 @@
charset = "utf-8";
indent_style = "tab";
indent_size = 2;
insert_final_newline = "true";
trim_trailing_whitespace = "true";
insert_final_newline = false;
trim_trailing_whitespace = true;
};
"Makefile" = {

View file

@ -4,29 +4,39 @@
manager = {
prepend_keymap = [
{
desc = "Dangerous life.";
on = "d";
run = "remove --permanently";
desc = "Dangerous life.";
}
{
desc = "Dangerous life.";
on = "D";
run = "remove --permanently --force";
desc = "Dangerous life.";
}
{
desc = "Who wants files anyway?";
on = "a";
run = "create --dir";
desc = "Who wants files anyway?";
}
{
desc = "I want, sometimes.";
on = "A";
run = "create --force";
desc = "I want, sometimes.";
}
{
desc = "Spawn shell here.";
on = "<Enter>";
run = ''shell "SHELL_NAME=yazi $SHELL" --block --confirm'';
desc = "Spawn shell here.";
}
{
desc = "Open interactively";
on = "o";
run = "open --interactive";
}
{
desc = "Open default";
on = "O";
run = "open";
}
];
};

View file

@ -39,7 +39,13 @@
archive = [
{
desc = "Archive";
run = openWith "unpack";
run = openWith "archive";
}
];
archive_fast = [
{
desc = "Archive Fast";
run = openWith "archive_fast";
}
];
audio = [
@ -118,13 +124,19 @@
run = openWith "funlock";
}
];
unpack = [
{
desc = "Unpack";
run = openWith "unpack";
}
];
};
open = {
rules =
let
defaultUse = [
"text"
"archive_fast"
"hex"
];
mkMime = mime: use: {
@ -139,11 +151,11 @@
[
# Use `file -i file.txt` to find file mime type.
# Use `xdg-mime query default "text/plain"` to find default app.
(mkMime "application/gzip" [ "archive" ])
(mkMime "application/x-tar" [ "archive" ])
(mkMime "application/x-xz" [ "archive" ])
(mkMime "application/zip" [ "archive" ])
(mkMime "application/x-7z-compressed" [ "archive" ])
(mkMime "application/gzip" [ "unpack" ])
(mkMime "application/x-tar" [ "unpack" ])
(mkMime "application/x-xz" [ "unpack" ])
(mkMime "application/zip" [ "unpack" ])
(mkMime "application/x-7z-compressed" [ "unpack" ])
(mkMime "application/x-iso9660-image" [ "mount" ])
(mkMime "application/x-raw-disk-image" [ "unlock" ])
(mkMime "application/pdf" [ "pdf" ])
@ -155,7 +167,10 @@
])
(mkMime "video/*" [ "video" ])
(mkMime "text/html" [ "browser" ])
(mkMime "text/*" [ "text" ])
(mkMime "application/vnd.openxmlformats-officedocument.*" [ "document" ])
(mkMime "inode/directory" [ "archive" ])
(mkMime "inode/x-empty" [ "text" ])
(mkMime "*" [ ])
];
};

View file

@ -363,7 +363,8 @@
# Check if file is an archive.
function _is_archive() {
local out=$(echo "''${*}" | grep -E ''${_archive_pattern})
local target="''${*}"
local out=$(echo "''${target##*/}" | grep -E ''${_archive_pattern})
[[ "''${out}" != "" ]]
}

View file

@ -10,7 +10,7 @@
process() {
# Skip archive.
if $(_is_archive ''${target}); then
if $(_is_archive "''${target}"); then
_iterate_skip "File is an archive, skip."
return 0
fi
@ -51,7 +51,7 @@
process() {
# Skip archive.
if $(_is_archive ''${target}); then
if $(_is_archive "''${target}"); then
_iterate_skip "File is an archive, skip."
return 0
fi

View file

@ -70,6 +70,12 @@
# Use full path to file.
target=''$(realpath "''${target}")
# Check for archive.
if $(_is_archive "''${target}"); then
unarchive "''${target}"
return 0
fi
# Unpack file type.
local type="''${target##*.}"