From 2dc3829b5cd75a18ec79da663884b5317e94dd7c Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Thu, 17 Oct 2024 22:38:47 +0300 Subject: [PATCH] Yazi: Improve openers. --- home/config/editorconfig/default.nix | 4 ++-- home/config/yazi/module/Keymap.nix | 20 ++++++++++++++----- home/config/yazi/module/Yazi.nix | 29 +++++++++++++++++++++------- home/program/bash/module/Archive.nix | 3 ++- home/program/bash/module/Name.nix | 4 ++-- home/program/bash/module/Pack.nix | 6 ++++++ 6 files changed, 49 insertions(+), 17 deletions(-) diff --git a/home/config/editorconfig/default.nix b/home/config/editorconfig/default.nix index 72018b6..36bbf0e 100644 --- a/home/config/editorconfig/default.nix +++ b/home/config/editorconfig/default.nix @@ -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" = { diff --git a/home/config/yazi/module/Keymap.nix b/home/config/yazi/module/Keymap.nix index 0fd9387..2f2a770 100644 --- a/home/config/yazi/module/Keymap.nix +++ b/home/config/yazi/module/Keymap.nix @@ -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 = ""; 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"; } ]; }; diff --git a/home/config/yazi/module/Yazi.nix b/home/config/yazi/module/Yazi.nix index 50e74e4..0107e98 100644 --- a/home/config/yazi/module/Yazi.nix +++ b/home/config/yazi/module/Yazi.nix @@ -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 "*" [ ]) ]; }; diff --git a/home/program/bash/module/Archive.nix b/home/program/bash/module/Archive.nix index 1916809..8abe055 100644 --- a/home/program/bash/module/Archive.nix +++ b/home/program/bash/module/Archive.nix @@ -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}" != "" ]] } diff --git a/home/program/bash/module/Name.nix b/home/program/bash/module/Name.nix index 2008cfe..ce33025 100644 --- a/home/program/bash/module/Name.nix +++ b/home/program/bash/module/Name.nix @@ -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 diff --git a/home/program/bash/module/Pack.nix b/home/program/bash/module/Pack.nix index 0e12b24..eaff272 100644 --- a/home/program/bash/module/Pack.nix +++ b/home/program/bash/module/Pack.nix @@ -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##*.}"