doronbehar / pistol

General purpose file previewer designed for Ranger, Lf to make scope.sh redundant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug: + symbol in mimetype

smhmd opened this issue · comments

application/epub+zip is the mimetype for .epub files.

# ~/.config/pistol/pistol.conf
application/epub+zip epub2txt -m --notext %s

This does not work and .epub files preview is the default one. it seems that the + symbol is unaccounted for. application/epub* fixes the issue.

As explained in the README, under #Syntax, Go's built-in regex library is used for mime type regex matching. Hence, it's syntax requires certain escaping to be used in order to match for example a literal +. Unfortunately, I couldn't find a clear evidence that + should be escaped in order to be matched literally. As a casual programmer though, I can testify that I've never encountered a regex syntax that didn't require escaping + with \ as so:

application/epub\+zip

Please test that just to verify I'm right. Also, thank you for mentioning this issue, do you think this could be explained better in the README?

application/epub\+zip works!

do you think this could be explained better in the README?

Yes, I think instead of explanation that WILL go over a first reader's head as "unnecessary details" just to fire thing up, a block of examples would be much better:

# ~/.config/pistol/pistol.conf
audio/* mediainfo %s                                                            # mimetype rule.
.md glow -s dark %s                                                               #  .extension rule.
application/pdf pdftotext -l 10 -nopgbrk -q -- %s -           # %s will be replaced with the file.
text/html w3m -T text/html -dump %s                               # more specific matches go on top
text/* cat %s                                                                           #  of generic ones. 
application/epub\+zip epub2txt -m --notext %s              # + symbol(s) should be escaped
Example Code

```fish
# ~/.config/pistol/pistol.conf
audio/* mediainfo %s                                                            # mimetype rule.
.md glow -s dark %s                                                               # .extension rule.
application/pdf pdftotext -l 10 -nopgbrk -q -- %s -           # %s will be replaced with the file.
text/html w3m -T text/html -dump %s                               # more specific matches go on top
text/* cat %s                                                                           # of generic ones.
application/epub+zip epub2txt -m --notext %s              # + symbol(s) should be escaped
```

I agree more examples are a good idea 👍. You can add examples to this wiki page, I'll add an appropriate comment with a link to the Readme.

Examples as in recommendations or illustrations tldr style? Because I think the explanations should go in the wiki or bottom of README, regardless, and illustrative examples (to get up and running) in the README, unless the examples are meant to be recommendations for preview commands, which would be great; to know what other people are using.

Recommendations could look like this:

Preview Commands:

Markdown: glow, mdcat.

Because The example here is not meant to be extensible but rather concise and to the point.

Usage

# ~/.config/pistol/pistol.conf
audio/* mediainfo %s                                                            # mimetype rule.
.md glow -s dark %s                                                               #  .extension rule.
application/pdf pdftotext -l 10 -nopgbrk -q -- %s -           # %s will be replaced with the file.
text/html w3m -T text/html -dump %s                               # more specific matches go on top
text/* cat %s                                                                           #  of generic ones. 
application/epub\+zip epub2txt -m --notext %s              # + symbol(s) should be escaped

The readme includes explanations. My intention is that the WiKi will give both regex examples and command recommendations. I'd put a url of the project's page of the command in use on top of each example. Note the config file doesn't support comments (for as far as I remember..). Just do whatever you feel right about that wiki page - that's the idea of a wiki.