batpipe: Add zip viewer

This commit is contained in:
Ethan P 2021-03-24 20:00:23 -07:00
parent 2a28cbff3a
commit 1734cedbd9
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
2 changed files with 25 additions and 2 deletions

View File

@ -25,6 +25,7 @@ Like [lesspipe](https://github.com/wofr06/lesspipe), `batpipe` is designed to wo
| -------------------- | --------------------------- | | -------------------- | --------------------------- |
| Directories | `ls` | | Directories | `ls` |
| `*.tar`, `*.tar.gz` | `tar` | | `*.tar`, `*.tar.gz` | `tar` |
| `*.zip`, `*.jar` | `unzip` |

View File

@ -109,7 +109,7 @@ fi
# Viewers: # Viewers:
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
BATPIPE_VIEWERS=("ls" "tar") BATPIPE_VIEWERS=("ls" "tar" "unzip")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -148,6 +148,29 @@ viewer_tar_process() {
fi fi
} }
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
viewer_unzip_supports() {
command -v "unzip" &> /dev/null || return 1
case "$2" in
*.zip) return 0 ;;
esac
return 1
}
viewer_unzip_process() {
if [[ -n "$2" ]]; then
unzip -p "$1" "$2" | bat_if_not_bat --file-name="$1/$2"
else
batpipe_header "Viewing contents of archive: %{PATH}%s" "$1"
batpipe_subheader "To view files within the archive, add the file path after the archive."
unzip -l "$1"
return $?
fi
}
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Functions: # Functions:
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -308,5 +331,4 @@ for viewer in "${BATPIPE_VIEWERS[@]}"; do
done done
# No supported viewer. Just pass it through. # No supported viewer. Just pass it through.
cat
exit 1 exit 1