Skip to content

Commit

Permalink
add support for appimage and snap files
Browse files Browse the repository at this point in the history
  • Loading branch information
wofr06 committed May 9, 2024
1 parent 6943662 commit 2a2d240
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
****************************************************************************
# ChangeLog for lesspipe.sh #
****************************************************************************
- added support for appimage and snap files
- respect color scheme setting of vim in vimcolor, add listing of file types
- improve xml (and html) display using the xmq binary
- fix color detection (-R) again
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ the author by email.
- Debian requires `bsdtar` or `ar`
- cab requires `cabextract` or `7z`
- cpio requires `cpio` or `bsdtar` or `7z`
- appimage requires `unsquashfs`
- snap requires `snap` and `unsquashfs`

### 4.2 List of preprocessed file types
- directory displayed using `ls -lA`
Expand Down
45 changes: 31 additions & 14 deletions lesscomplete
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# lesscomplete, a helper script for the _less completion script
# synced with lesspipe 2.12
# Author: Wolfgang Friebel (wp.friebel AT gmail.com)
#( [[ -n 1 && -n 2 ]] ) > /dev/null 2>&1 || exec zsh -y --ksh-arrays -- "$0" ${1+"$@"}

has_cmd () {
command -v "$1" > /dev/null
Expand All @@ -11,9 +10,9 @@ has_cmd () {
fileext () {
fn=${1##*/}
case "$fn" in
.*.*) extension=${fn##*.};;
.*) extension=;;
*.*) extension=${fn##*.};;
.*.*) extension=${fn##*.} ;;
.*) extension= ;;
*.*) extension=${fn##*.} ;;
esac
echo "$extension"
}
Expand All @@ -37,15 +36,20 @@ filetype () {
ft="${ft#*/}"; ft="${ft%;*}"; ft="${ft#x-script.}"; ft="${ft#x-}"
ftype="${ft#vnd\.}"
### get file type from 'file' command for an unspecific result
if [[ "$fcat" == application && "$ftype" == octet-stream || "$fcat" == text && $ftype == plain ]]; then
ft=$(file -L -s -b "$1" 2> /dev/null)
if [[ $ft == data ]]; then
case "$fext" in
br|bro|tbr)
ftype=brotli ;;
lz4|lt4|tz4|tlz4)
ftype=lz4 ;;
esac
if [[ "$fcat" == application ]]; then
if [[ "$ftype" == octet-stream || "$fcat" == text && $ftype == plain ]]; then
ft=$(file -L -s -b "$1" 2> /dev/null)
if [[ $ft == data ]]; then
case "$fext" in
br|bro|tbr)
ftype=brotli ;;
lz4|lt4|tz4|tlz4)
ftype=lz4 ;;
esac
fi
fi
if [[ "$fext" == appimage || "$fext" == snap ]]; then
ftype="$fext"
fi
fi

Expand Down Expand Up @@ -218,7 +222,9 @@ get_unpack_cmd () {
{ has_cmd bsdtar && prog=bsdtar; } ;;
archive)
prog='ar'
has_cmd bsdtar && prog=bsdtar
has_cmd bsdtar && prog=bsdtar ;;
appimage|snap)
has_cmd unsquashfs && cmd=(isimage "$x" "$2" "$file2") ;;
esac
# 7z formats and fall back to 7z supported formats
if [[ -z $prog ]]; then
Expand Down Expand Up @@ -301,6 +307,17 @@ cabextract2 () {
cabextract -pF "$2" "$1"
}

isimage () {
if [[ "$1" == appimage ]]; then
offset="-o $("$2" --appimage-offset)"
fi
if [[ -z "$3" ]]; then
istemp "unsquashfs -d . -lc $offset" "$2"
else
istemp "unsquashfs -cat $offset" "$2" "$3"
fi
}

isrpm () {
if [[ -z "$2" ]]; then
if has_cmd bsdtar; then
Expand Down
3 changes: 2 additions & 1 deletion lesspipe.1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ 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, 7-zip, rar, jar, cpio, rpm, deb ms-cabinet and iso formats\fP).
(\fItar, ar, zip, 7-zip, rar, jar, cpio, rpm, deb ms-cabinet, iso, appimage
and snap 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, xml\fP and \fImedia (image, audio and
Expand Down
23 changes: 22 additions & 1 deletion lesspipe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ filetype () {
[[ $fcat == text ]] && ftype="$fext" ;;
tsx)
[[ $fcat == text ]] && ftype=typescript-jsx ;;
appimage)
[[ $fcat == application && -x "$1" ]] && ftype="$fext" ;;
snap)
[[ $fcat == application ]] && ftype="$fext" ;;
esac
### get file type from 'file' command for an unspecific result
if [[ "$fcat" == message && $ftype == plain ]]; then
Expand Down Expand Up @@ -365,7 +369,9 @@ get_unpack_cmd () {
{ has_cmd bsdtar && prog=bsdtar; } ;;
archive)
prog='ar'
has_cmd bsdtar && prog=bsdtar
has_cmd bsdtar && prog=bsdtar ;;
appimage|snap)
has_cmd unsquashfs && cmd=(isimage "$x" "$2" "$file2") ;;
esac
# 7z formats and fall back to 7z supported formats
if [[ -z $prog ]]; then
Expand Down Expand Up @@ -703,6 +709,21 @@ ispdf () {
istemp pdftohtml -i -q -s -noframes -nodrm -stdout "$1"|ishtml -
}

isimage () {
if [[ "$1" == appimage ]]; then
offset="-o $("$2" --appimage-offset)"
fi
if [[ -z "$3" ]]; then
if [[ "$1" == snap ]]; then
has_cmd snap && snap info "$2"
separatorline
fi
istemp "unsquashfs -d . -llc $offset" "$2"
else
istemp "unsquashfs -cat $offset" "$2" "$3"
fi
}

isrpm () {
if [[ -z "$2" ]]; then
if has_cmd rpm; then
Expand Down

0 comments on commit 2a2d240

Please sign in to comment.