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"; charset = "utf-8";
indent_style = "tab"; indent_style = "tab";
indent_size = 2; indent_size = 2;
insert_final_newline = "true"; insert_final_newline = false;
trim_trailing_whitespace = "true"; trim_trailing_whitespace = true;
}; };
"Makefile" = { "Makefile" = {

View file

@ -4,29 +4,39 @@
manager = { manager = {
prepend_keymap = [ prepend_keymap = [
{ {
desc = "Dangerous life.";
on = "d"; on = "d";
run = "remove --permanently"; run = "remove --permanently";
desc = "Dangerous life.";
} }
{ {
desc = "Dangerous life.";
on = "D"; on = "D";
run = "remove --permanently --force"; run = "remove --permanently --force";
desc = "Dangerous life.";
} }
{ {
desc = "Who wants files anyway?";
on = "a"; on = "a";
run = "create --dir"; run = "create --dir";
desc = "Who wants files anyway?";
} }
{ {
desc = "I want, sometimes.";
on = "A"; on = "A";
run = "create --force"; run = "create --force";
desc = "I want, sometimes.";
} }
{ {
desc = "Spawn shell here.";
on = "<Enter>"; on = "<Enter>";
run = ''shell "SHELL_NAME=yazi $SHELL" --block --confirm''; 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 = [ archive = [
{ {
desc = "Archive"; desc = "Archive";
run = openWith "unpack"; run = openWith "archive";
}
];
archive_fast = [
{
desc = "Archive Fast";
run = openWith "archive_fast";
} }
]; ];
audio = [ audio = [
@ -118,13 +124,19 @@
run = openWith "funlock"; run = openWith "funlock";
} }
]; ];
unpack = [
{
desc = "Unpack";
run = openWith "unpack";
}
];
}; };
open = { open = {
rules = rules =
let let
defaultUse = [ defaultUse = [
"text" "archive_fast"
"hex" "hex"
]; ];
mkMime = mime: use: { mkMime = mime: use: {
@ -139,11 +151,11 @@
[ [
# Use `file -i file.txt` to find file mime type. # Use `file -i file.txt` to find file mime type.
# Use `xdg-mime query default "text/plain"` to find default app. # Use `xdg-mime query default "text/plain"` to find default app.
(mkMime "application/gzip" [ "archive" ]) (mkMime "application/gzip" [ "unpack" ])
(mkMime "application/x-tar" [ "archive" ]) (mkMime "application/x-tar" [ "unpack" ])
(mkMime "application/x-xz" [ "archive" ]) (mkMime "application/x-xz" [ "unpack" ])
(mkMime "application/zip" [ "archive" ]) (mkMime "application/zip" [ "unpack" ])
(mkMime "application/x-7z-compressed" [ "archive" ]) (mkMime "application/x-7z-compressed" [ "unpack" ])
(mkMime "application/x-iso9660-image" [ "mount" ]) (mkMime "application/x-iso9660-image" [ "mount" ])
(mkMime "application/x-raw-disk-image" [ "unlock" ]) (mkMime "application/x-raw-disk-image" [ "unlock" ])
(mkMime "application/pdf" [ "pdf" ]) (mkMime "application/pdf" [ "pdf" ])
@ -155,7 +167,10 @@
]) ])
(mkMime "video/*" [ "video" ]) (mkMime "video/*" [ "video" ])
(mkMime "text/html" [ "browser" ]) (mkMime "text/html" [ "browser" ])
(mkMime "text/*" [ "text" ])
(mkMime "application/vnd.openxmlformats-officedocument.*" [ "document" ]) (mkMime "application/vnd.openxmlformats-officedocument.*" [ "document" ])
(mkMime "inode/directory" [ "archive" ])
(mkMime "inode/x-empty" [ "text" ])
(mkMime "*" [ ]) (mkMime "*" [ ])
]; ];
}; };

View file

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

View file

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

View file

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