batpipe: Extract batpipe_archive_header() helper function

This commit is contained in:
Adam Spiers 2023-08-03 16:49:03 +01:00
parent ceaac1b917
commit 4c220a84a3

View File

@ -202,8 +202,7 @@ viewer_tar_process() {
if [[ -n "$2" ]]; then
tar -xf "$1" -O "$2" | 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."
batpipe_archive_header
tar -tvf "$1"
return $?
fi
@ -225,8 +224,7 @@ viewer_unzip_process() {
if [[ -n "$2" ]]; then
unzip -p "$1" "$2" | 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."
batpipe_archive_header
unzip -l "$1"
return $?
fi
@ -290,6 +288,11 @@ batpipe_subheader() {
printc "%{SUBHEADER}==> $pattern%{C}\n" "${@:2}"
}
batpipe_archive_header() {
batpipe_header "Viewing contents of archive: %{PATH}%s" "$1"
batpipe_subheader "To view files within the archive, add the file path after the archive."
}
# Executes `bat` (or `cat`, if already running from within `bat`).
# Supports the `--file-name` argument if the bat version is new enough.
#