]> Sergey Matveev's repositories - dotfiles.git/commitdiff
Ability for prefix aliases to work with compressed files
authorSergey Matveev <stargrave@stargrave.org>
Fri, 18 Mar 2022 14:16:38 +0000 (17:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Fri, 18 Mar 2022 14:16:38 +0000 (17:16 +0300)
zsh/.zsh/rc/010mime.zsh
zsh/bin/zsh-mime-open

index 5711884379bfa58e912ca13a6f067e4960ff4d71..221bdf7cbc73a2435fcfe066768e19bc41a28689 100644 (file)
@@ -1,2 +1,22 @@
 autoload -U zsh-mime-setup ; zsh-mime-setup
+
+mime_compressed_handler() {
+    local tmp=`mktemp -t zsh-mime`
+    mv $tmp $tmp.$1:r:e
+    tmp=$tmp.$1:r:e
+    case $1:e in
+    (bz2) bunzip2 < $1 > $tmp ;;
+    (gz) gunzip < $1 > $tmp ;;
+    (xz) unxz < $1 > $tmp ;;
+    (zst) unzstd < $1 > $tmp ;;
+    (*) exit 1 ;;
+    esac
+    zsh-mime-handler $tmp
+}
+
+alias -s bz2=mime_compressed_handler
+alias -s gz=mime_compressed_handler
+alias -s xz=mime_compressed_handler
+alias -s zst=mime_compressed_handler
+
 alias -s html=lynx
index 7c7cecbae08979f4652d542a5770af25190b2479..990b59ff16d4fa3c423bf4406ea818448f61dc18 100755 (executable)
@@ -1,5 +1,4 @@
 #!/usr/bin/env zsh
 
-autoload -U zsh-mime-setup
-zsh-mime-setup
+. ~/.zsh/rc/010mime.zsh
 zsh-mime-handler $1