Less snap, more awesome

Did you ever, like me, get frustrated when trying to peek at a snap that’s on your disk and hit the dreaded

$ less foo_bar_1.snap
"foo_bar_1.snap" may be a binary file.  See it anyway? 

Rejoice, for now I have wrangled lessfilter so it’s now more like:

$ less go_1016.snap
path:    "go_1016.snap"
name:    go
summary: Go programming language compiler, linker, stdlib
version: 1.9.2 classic

*** Contents:
Parallel unsquashfs: Using 8 processors
6992 inodes (8233 blocks) to write

drwxr-xr-x root/root               426 2017-10-26 01:25 
-rw-r--r-- root/root             41258 2017-10-26 01:23 /AUTHORS
-rw-r--r-- root/root              1576 2017-10-26 01:23 /CONTRIBUTING.md
-rw-r--r-- root/root             55577 2017-10-26 01:23 /CONTRIBUTORS
-rw-r--r-- root/root              1479 2017-10-26 01:23 /LICENSE
-rw-r--r-- root/root              1303 2017-10-26 01:23 /PATENTS
-rw-r--r-- root/root              1601 2017-10-26 01:23 /README.md
-rw-r--r-- root/root                 7 2017-10-26 01:23 /VERSION
drwxr-xr-x root/root               231 2017-10-26 01:25 /api
-rw-r--r-- root/root               521 2017-10-26 01:23 /api/README

... <snip>

If you too want this awesomeness, then, open up ~/.lessfilter in your favourite editor and add the following:

#!/bin/sh

case "$1" in
    *.snap)
        if [ -x "`which snap`" ]; then snap info "$1"; fi
        if [ -x "`which unsquashfs`" ]; then
            echo
            echo '*** Contents:'; unsquashfs -ll -d '' "$1" 
        else echo "No unsquashfs available"; fi ;;
     *)
         exit 1
esac

Not forgetting to make it executable (thanks @popey) - chmod +x ~/.lessfilter

Edit: now with -ll for filesystem attributes = more awesomeness

9 Likes

Handy! Note, if it wasn’t obvious, that you have to make ~/.lessfilter executable with chmod +x ~/.lessfilter or it won’t work.

Ah yes, my editor will automatically prompt me to do that because of the #!, but I recognise some people worship the other $DEITIES.

Will update post to clarify - thanks!

Now you volunteered to make a classic less-snap with that included, right ? :wink:

Thanks, this is great! I uploaded the snap support to less in bionic now so that this works out of the box.

2 Likes

TIL less has a default filter mechanism, and that people actually use it. :slight_smile:

1 Like

Is it possible to get this into the core18/core20 snaps so that this works on UC18 and eventually UC20 machines? It works on 18.04 classic for me, but not on UC18.