Skip to content

Commit

Permalink
add support for cpio archives
Browse files Browse the repository at this point in the history
  • Loading branch information
wofr06 committed Mar 24, 2024
1 parent 6df3188 commit 89fa898
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 18 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
****************************************************************************
# ChangeLog for lesspipe.sh #
****************************************************************************
- support for cpio archives
- fall back to 7z for supported formats
Version 2.12 Mar 18 2024
- improve completion for file names with special chars
- better output when using xlscat
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ the author by email.
### 4.1 Supported compression methods and archive formats
- gzip, compress requires `gzip`
- bzip2 requires `bzip2`
- lzma requires `lzma`
- xz requires `xz`
- lzma requires `lzma` or `7z`
- xz requires `xz` or `7z`
- zstd requires `zstd`
- brotli requires `bro`
- lz4 requires `lz4`
Expand All @@ -200,10 +200,11 @@ the author by email.
- rar archive requires `bsdtar` or `unrar` or `rar`
- 7-zip archive requires `7zz` or `7zr` or `7z` or `7za`
- lzip archive requires `lzip`
- iso images requires `bsdtar` or `isoinfo`
- iso images requires `bsdtar` or `isoinfo` or `7z`
- rpm requires `rpm2cpio` and `cpio` or `bsdtar`
- Debian requires `bsdtar` or `ar`
- cab requires `cabextract`
- cab requires `cabextract` or `7z`
- cpio requires `cpio` or `bsdtar` or `7z`

### 4.2 List of preprocessed file types
- directory displayed using `ls -lA`
Expand Down
30 changes: 25 additions & 5 deletions lesscomplete
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,26 @@ get_unpack_cmd () {
ms-cab-compressed)
{ has_cmd bsdtar && prog=bsdtar; } ||
{ has_cmd cabextract && prog=cabextract; } ;;
7z-compressed)
{ has_cmd 7zz && prog=7zz; } ||
{ has_cmd 7zr && prog=7zr; } ||
{ has_cmd 7z && prog=7z; } ||
{ has_cmd 7za && prog=7za; } ;;
iso9660-image)
{ has_cmd bsdtar && prog=bsdtar; } ||
{ has_cmd isoinfo && prog=isoinfo; } ;;
cpio)
{ has_cmd cpio && prog=cpio; } ||
{ has_cmd bsdtar && prog=bsdtar; } ;;
archive)
prog='ar'
has_cmd bsdtar && prog=bsdtar
esac
# 7z formats and fall back to 7z supported formats
if [[ -z $prog ]]; then
case "$x" in
7z-compressed|lzma|xz|cab|arj|bzip2|cpio|iso)
{ has_cmd 7zz && prog=7zz; } ||
{ has_cmd 7zr && prog=7zr; } ||
{ has_cmd 7z && prog=7z; } ||
{ has_cmd 7za && prog=7za; } ;;
esac
fi
[[ -n $prog ]] && cmd=(isarchive "$prog" "$2" "$file2")
if [[ -n ${cmd[0]} ]]; then
[[ -n "$file2" ]] && file2= && return
Expand Down Expand Up @@ -251,6 +259,12 @@ isarchive () {
istemp cabextract2 "$2" "$3" ;;
isoinfo)
istemp "isoinfo -i" "$2" "-x$3" ;;
cpio)
if [[ "$2" == - ]]; then
cpio -i --quiet --to-stdout "$3"
else
cpio -i --quiet --to-stdout --file "$2" "$3"
fi ;;
7zz|7za|7zr)
istemp "$prog e -so" "$2" "$3"
esac
Expand All @@ -271,6 +285,12 @@ isarchive () {
istemp "isoinfo -d -i" "$2" >/dev/null
istemp "isoinfo -d -i" "$t"| grep -E '^Joliet' && joliet=J
isoinfo -fR"$joliet" -i "$t" ;;
cpio)
if [[ "$2" == - ]]; then
cpio -t --quiet
else
cpio -t --quiet --file "$2"
fi ;;
7zz|7za|7zr)
istemp "$prog l" "$2"|grep -E '^[0-9][0-9][0-9[0-9]'|cut -c 54-|grep -Ev ' files$'
esac
Expand Down
2 changes: 1 addition & 1 deletion lesspipe.1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ With the help of that filter \fBless\fP
will display the uncompressed contents of compressed (\fIgzip, bzip2,
compress, zstd, lz4, lzip, xz, lzma or brotli\fP) files. For files
containing archives and directories, a table of contents will be displayed
(\fItar, ar, zip, i7-zip, rar, jar, rpm, deb ms-cabinet and iso formats\fP).
(\fItar, ar, zip, i7-zip, rar, jar, cpio, rpm, deb ms-cabinet and iso formats\fP).
Many other files will be reformatted for display. It includes
\fIpdf, dvi, markdown, Office (MS and Openoffice)\fP suites formats,
\fINetCDF, matlab, device tree blob, html\fP and \fImedia (image, audio and
Expand Down
30 changes: 25 additions & 5 deletions lesspipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -370,18 +370,26 @@ get_unpack_cmd () {
ms-cab-compressed)
{ has_cmd bsdtar && prog=bsdtar; } ||
{ has_cmd cabextract && prog=cabextract; } ;;
7z-compressed)
{ has_cmd 7zz && prog=7zz; } ||
{ has_cmd 7zr && prog=7zr; } ||
{ has_cmd 7z && prog=7z; } ||
{ has_cmd 7za && prog=7za; } ;;
iso9660-image)
{ has_cmd bsdtar && prog=bsdtar; } ||
{ has_cmd isoinfo && prog=isoinfo; } ;;
cpio)
{ has_cmd cpio && prog=cpio; } ||
{ has_cmd bsdtar && prog=bsdtar; } ;;
archive)
prog='ar'
has_cmd bsdtar && prog=bsdtar
esac
# 7z formats and fall back to 7z supported formats
if [[ -z $prog ]]; then
case "$x" in
7z-compressed|lzma|xz|cab|arj|bzip2|cpio|iso)
{ has_cmd 7zz && prog=7zz; } ||
{ has_cmd 7zr && prog=7zr; } ||
{ has_cmd 7z && prog=7z; } ||
{ has_cmd 7za && prog=7za; } ;;
esac
fi
[[ -n $prog ]] && cmd=(isarchive "$prog" "$2" "$file2")
if [[ -n ${cmd[*]} ]]; then
[[ -n "$file2" ]] && file2= && return
Expand Down Expand Up @@ -656,6 +664,12 @@ isarchive () {
istemp cabextract2 "$2" "$3" ;;
isoinfo)
istemp "isoinfo -i" "$2" "-x$3" ;;
cpio)
if [[ "$2" == - ]]; then
cpio -i --quiet --to-stdout "$3"
else
cpio -i --quiet --to-stdout --file "$2" "$3"
fi ;;
7zz|7za|7zr)
istemp "$prog e -so" "$2" "$3"
esac
Expand All @@ -678,6 +692,12 @@ isarchive () {
isoinfo -d -i "$t"| grep -E '^Joliet' && joliet=J
separatorline
isoinfo -fR"$joliet" -i "$t" ;;
cpio)
if [[ "$2" == - ]]; then
cpio -tv --quiet
else
cpio -tv --quiet --file "$2"
fi ;;
7zz|7za|7zr)
istemp "$prog l" "$2"
esac
Expand Down
6 changes: 3 additions & 3 deletions test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ sub comp {
= test
less tests/archive.tgz:test_ar:a=b # (on the fly)
= test
less tests/archive.tgz:test_cpio:textfile # (on the fly) needs cpio
= test
### uncompress tests not covered in archive tests
less tests/compress.tgz:test.tar.bz2:tests/textfile # extract from bzip2
= test
Expand Down Expand Up @@ -381,9 +383,7 @@ sub comp {
~ .* T test
less tests/filter.tgz:test.pod # pod text, needs pod2text|perldoc
~ test
less tests/filter.tgz:test.pod # perl storable, needs perl
~ test
less tests/filter.tgz:test.pod: # unmodified pod text, needs pod2text|perldoct
less tests/filter.tgz:test.pod: # unmodified pod text, needs pod2text|perldoc
~ test
less tests/filter.tgz:test_nc4 # netcdf, needs h5dump|ncdump
~ data:|\s*DATA .
Expand Down
Binary file modified tests/archive.tgz
Binary file not shown.

0 comments on commit 89fa898

Please sign in to comment.