Skip to content

Commit

Permalink
feat(batpipe): Add support for more file formats
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Jul 16, 2024
1 parent aef5a42 commit 2fbe9fc
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 2 deletions.
6 changes: 6 additions & 0 deletions doc/batpipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ Like [lesspipe](https://github.com/wofr06/lesspipe), `batpipe` is designed to wo
| Directories | `eza`, `ls` |
| `*.tar`, `*.tar.gz` | `tar` |
| `*.zip`, `*.jar` | `unzip` |
| `*.7z` | `7z` |
| `*.gz` | `gunzip` |
| `*.bz2` | `bzip2` |
| `*.xz` | `xz` |
| `*.lz4` | `lz4` |
| `*.lz` | `lzip` |
| `*.lzo` | `lzop` |
| `*.zst` | `zstd` |


## External Viewers
Expand Down
150 changes: 148 additions & 2 deletions src/batpipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ fi

if ! command -v eza &> /dev/null
then
BATPIPE_VIEWERS=("eza" "ls" "tar" "tar_gz" "unzip" "gunzip" "xz")
BATPIPE_VIEWERS=("eza" "ls" "tar" "tar_gz" "tar_bz2" "tar_xz" "tar_zst" "unzip" "7z" "gunzip" "bzip2" "xz" "lz4" "lzip" "lzop" "zstd")
else
BATPIPE_VIEWERS=("exa" "ls" "tar" "tar_bz2" "unzip" "gunzip" "xz")
BATPIPE_VIEWERS=("exa" "ls" "tar" "tar_gz" "tar_bz2" "tar_xz" "tar_zst" "unzip" "7z" "gunzip" "bzip2" "xz" "lz4" "lzip" "lzop" "zstd")
fi

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -265,6 +265,40 @@ viewer_tar_bz2_process() {

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_tar_xz_supports() {
command -v "tar" &> /dev/null || return 1
command -v "xz" &> /dev/null || return 1

case "$1" in
*.tar.xz | *.txz) return 0 ;;
esac

return 1
}

viewer_tar_xz_process() {
viewer_tar_process "$1" "$2" -J
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_tar_zst_supports() {
command -v "tar" &> /dev/null || return 1
command -v "zstd" &> /dev/null || return 1

case "$1" in
*.tar.zst | *.tzst) return 0 ;;
esac

return 1
}

viewer_tar_zst_process() {
viewer_tar_process "$1" "$2" --zstd
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_unzip_supports() {
command -v "unzip" &> /dev/null || return 1

Expand All @@ -287,6 +321,28 @@ viewer_unzip_process() {

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_7z_supports() {
command -v "7z" &> /dev/null || return 1

case "$1" in
*.7z) return 0 ;;
esac

return 1
}

viewer_7z_process() {
if [[ -n "$2" ]]; then
7z x -so "$1" "$2" | bat --file-name="$1/$2"
else
batpipe_archive_header
7z l "$1"
return $?
fi
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_gunzip_supports() {
command -v "gunzip" &> /dev/null || return 1
[[ -z "$3" ]] || return 1
Expand All @@ -305,6 +361,24 @@ viewer_gunzip_process() {

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_bzip2_supports() {
command -v "bzip2" &> /dev/null || return 1
[[ -z "$3" ]] || return 1

case "$2" in
*.bz2) return 0 ;;
esac

return 1
}

viewer_bzip2_process() {
bzip2 -d -k -c "$1" | bat --file-name="$1"
return $?
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_xz_supports() {
command -v "xz" &> /dev/null || return 1
[[ -z "$3" ]] || return 1
Expand All @@ -321,6 +395,78 @@ viewer_xz_process() {
return $?
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_lz4_supports() {
command -v "lz4" &> /dev/null || return 1
[[ -z "$3" ]] || return 1

case "$2" in
*.lz4) return 0 ;;
esac

return 1
}

viewer_lz4_process() {
lz4 -d -c "$1" | bat --file-name="$1"
return $?
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_lzip_supports() {
command -v "lzip" &> /dev/null || return 1
[[ -z "$3" ]] || return 1

case "$2" in
*.lz) return 0 ;;
esac

return 1
}

viewer_lzip_process() {
lzip -d -c "$1" | bat --file-name="$1"
return $?
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_lzop_supports() {
command -v "lzop" &> /dev/null || return 1
[[ -z "$3" ]] || return 1

case "$2" in
*.lzo) return 0 ;;
esac

return 1
}

viewer_lzop_process() {
lzop -d -c "$1" | bat --file-name="$1"
return $?
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

viewer_zstd_supports() {
command -v "zstd" &> /dev/null || return 1
[[ -z "$3" ]] || return 1

case "$2" in
*.zst) return 0 ;;
esac

return 1
}

viewer_zstd_process() {
zstd -d -c "$1" | bat --file-name="$1"
return $?
}

# -----------------------------------------------------------------------------
# Functions:
# -----------------------------------------------------------------------------
Expand Down

0 comments on commit 2fbe9fc

Please sign in to comment.