From 988780bce94985392856b95f8770ee611e9c1260 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Wed, 24 Mar 2021 20:06:10 -0700 Subject: [PATCH] batpipe: Add support for *.gz files --- doc/batpipe.md | 2 +- src/batpipe.sh | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/batpipe.md b/doc/batpipe.md index 7d8e4fd..fb63337 100644 --- a/doc/batpipe.md +++ b/doc/batpipe.md @@ -26,7 +26,7 @@ Like [lesspipe](https://github.com/wofr06/lesspipe), `batpipe` is designed to wo | Directories | `ls` | | `*.tar`, `*.tar.gz` | `tar` | | `*.zip`, `*.jar` | `unzip` | - +| `*.gz` | `gunzip` | ## External Viewers diff --git a/src/batpipe.sh b/src/batpipe.sh index 1ff0767..776f2e8 100755 --- a/src/batpipe.sh +++ b/src/batpipe.sh @@ -109,7 +109,7 @@ fi # Viewers: # ----------------------------------------------------------------------------- -BATPIPE_VIEWERS=("ls" "tar" "unzip") +BATPIPE_VIEWERS=("ls" "tar" "unzip" "gunzip") # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -171,6 +171,24 @@ viewer_unzip_process() { fi } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +viewer_gunzip_supports() { + command -v "gunzip" &> /dev/null || return 1 + [[ -z "$3" ]] || return 1 + + case "$2" in + *.gz) return 0 ;; + esac + + return 1 +} + +viewer_gunzip_process() { + gunzip -k -c "$1" + return $? +} + # ----------------------------------------------------------------------------- # Functions: # -----------------------------------------------------------------------------