mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 19:57:46 +02:00
batpipe: Add zip viewer
This commit is contained in:
parent
2a28cbff3a
commit
1734cedbd9
@ -25,6 +25,7 @@ Like [lesspipe](https://github.com/wofr06/lesspipe), `batpipe` is designed to wo
|
||||
| -------------------- | --------------------------- |
|
||||
| Directories | `ls` |
|
||||
| `*.tar`, `*.tar.gz` | `tar` |
|
||||
| `*.zip`, `*.jar` | `unzip` |
|
||||
|
||||
|
||||
|
||||
|
@ -109,7 +109,7 @@ fi
|
||||
# Viewers:
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
BATPIPE_VIEWERS=("ls" "tar")
|
||||
BATPIPE_VIEWERS=("ls" "tar" "unzip")
|
||||
|
||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
@ -148,6 +148,29 @@ viewer_tar_process() {
|
||||
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:
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -308,5 +331,4 @@ for viewer in "${BATPIPE_VIEWERS[@]}"; do
|
||||
done
|
||||
|
||||
# No supported viewer. Just pass it through.
|
||||
cat
|
||||
exit 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user