GithubHelp home page GithubHelp logo

doronbehar / pistol Goto Github PK

View Code? Open in Web Editor NEW
298.0 7.0 7.0 229 KB

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

License: MIT License

Go 60.91% Makefile 8.16% Nix 17.40% Shell 13.53%

pistol's Introduction

Pistol

Introduction

Pistol is a file previewer for command line file managers such as Ranger, Lf and nnn, intended to replace the file previewer shell script scope.sh commonly used with Ranger and other previewing methods.

scope.sh is a Bash script that uses case switches and external programs to decide how to preview every file it encounters. It knows how to handle every file according to its MIME type and/or file extension using case switches and external programs. This design makes it hard to configure / maintain and it makes it slow for startup and heavy when running.

Pistol is a Go program (with (almost) 0 dependencies) and its MIME type detection is internal. Moreover, it features native preview support for almost any archive file and for text files along with syntax highlighting while scope.sh relies on external programs to do these basic tasks.

The following table lists Pistol’s native previewing support:

File/MIME Type Notes on implementation

text/*

Prints text files with syntax highlighting thanks to chroma.

Archives

Prints the contents of archive files using archiver.

In case Pistol encounters a MIME type it doesn’t know how to handle natively and you haven’t configured a program to handle it, it’ll print a general description of the file type it encountered. For example, the preview for an executable might be:

ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=a34861a1ae5358dc1079bc239df9dfe4830a8403, for GNU/Linux 3.2.0, not stripped

This feature is available out of the box just like the previews for the common mime types mentioned above.

See also the WiKi article: Pistol out in the Wild.

A Note on MIME type Detection

Some pure Go libraries provide MIME type detection. Here are the top search results I got using a common web search engine:

Pistol uses the last one which leverages the well known C library libmagic(3). I made this choice after experimenting with the other candidates and due to their lack of an extensive database such as libmagic(3) has, I chose magicmime.

Note that this choice also features compatibility with the standard command file which is available by default on most GNU/Linux distributions.[1]

A Note on Archive Previews

Pistol previews all archive / compression formats supported by the Go library archiver. Some formats do nothing but compression, meaning they operate on 1 file alone and some files are a combination of archive, compressed in a certain algorithm.

For example, a .gz file is a single file compressed with gzip. A .tar file is an uncompressed archive (collection) of files. A .tar.gz is a .tar file compressed using gzip.

When pistol encounters a single file compressed using a known compression algorithm, it doesn’t know how to handle its content, it displays the type of the archive. If a known compression algorithm has compressed a .tar file, Pistol lists the files themselves.

brotli compressed archives, (.tar.br) and Brotli compressed files (.br) are not detected by libmagic so Pistol doesn’t know how to handle them.[2]

Install

If someone has packaged Pistol for your distribution, you might find a package for of it linked in the WiKi.

If not, use the following instructions, or grab a statically compiled version of it from the releases page, available since version 0.3.1. The releases assets include also the manual page pistol.1.gz.

Warning
Currently, Darwin compatible binaries are not available there, but it should be possible to generate them via CI. All other binaries were cross compiled from my own x86_64 linux machine, using Nix' superb cross compilation support.
Note
For a statically compiled Pistol to be functional, it needs to read a libmagic database (usually found in /usr/share/misc/magic.mgc) and the static executable includes the contents of this database found on Nixpkgs' file package. The content of the magic.mgc database is copied to ~/.local/share/pistol/${libmagic-version}.mgc when you first run the executable. Hence using this executable might not be desirable due to this behaviour which a regular compilation of pistol does not include. This behaviour is compiled into pistol if you use go {build,install} with -tags EMBED_MAGIC_DB.

From Source

Since Pistol depends on magicmime, you’ll need a libmagic package installed. Please refer to this section in Magicmime’s README for the appropriate commands for every OS. In particular, if you installed libmagic using brew on a Darwin system, you may need to use the CGO_FLAGS environment variable to compile pistol. See #6 for more details.

Assuming you’ve installed libmagic properly and you have setup a Go environment, Use the following command to install Pistol to $GOPATH/bin/pistol:

Go 1.16 or later

go install github.com/doronbehar/pistol/cmd/pistol@latest

Go 1.15 or earlier

env CGO_ENABLED=1 GO111MODULE=on go get -u github.com/doronbehar/pistol/cmd/pistol

[3]

Besides libmagic, asciidoctor is also recommended, in order to compile the README as a manpage and install it. NixOS For instance, does it like this:

  # ...
  nativeBuildInputs = [
    installShellFiles
    asciidoctor
  ];
  postInstall = ''
    asciidoctor -b manpage -d manpage README.adoc
    installManPage pistol.1
  '';
  # ...

Link to currently evaluated file on NixOS. Packagers for other distros should do something similar.

Usage

$ pistol --help
Usage: pistol OPTIONS <file> [<extras> ...]

OPTIONS

-V, --version               Print version date and exit
-c, --config <config file>  configuration file to use (defaults to ~/.config/pistol/pistol.conf on Linux)
-h, --help                  print help and exit

ARGUMENTS

file                        the file to preview
extras                      extra arguments passed to the command

Integrations

Ranger / Lf

You can use Pistol as a file previewer in Ranger and Lf. For Ranger, set your preview_script in your rc.conf as follows:

set preview_script ~/.go/bin/pistol

The same goes for Lf, but in lfrc:

set previewer ~/.go/bin/pistol

fzf

If you use fzf to search for files, you can tell it to use pistol as the previewer. For example, the following command edits with your $EDITOR selected python file(s) using pistol as a previewer:

$EDITOR "$(find -name '*.py' | fzf --preview='pistol {}')"

Configuration

Although Pistol previews files of certain MIME types by default, it doesn’t force you to use these internal previewers for these MIME types. You can change this behaviour by writing a configuration file in ~/.config/pistol/pistol.conf (or $XDG_CONFIG_HOME/pistol/pistol.conf) On GNU systems, with the syntax as explained below.

Note
On OS X, this location defaults to: ~/Library/Preferences/pistol/pistol.conf, as the XDG specification imposes.

Syntax

You can configure preview commands according to file path or mime type regex. The 1st word may is always interpreted first as a mime type regex such as: text/*.

If a line is not matched but the 1st word is exactly fpath, then the 2nd argument is interpreted as a file path regex, such as: /var/src/.*/README.md.

On every line, whether you used fpath or not, the next arguments are the command’s arguments, where %pistol-filename% is substituted by pistol to the file at question. You’ll see more examples in the following sections.

Both regular expressions (for file paths and for mime types) are interpreted by the built-in library’s regexp.match. Please refer to this link for the full reference regarding syntax.

Matching Mime Types

You can inspect the MIME type of any file on a GNU/Linux OS and on Mac OS with the command file --mime-type <file>.

For example, say you wish to replace Pistol’s internal text previewer with that of bat’s, you’d put the following in your pistol.conf:

text/* bat --paging=never --color=always %pistol-filename%

Naturally, your configuration file overrides the internal previewers.

Here’s another example which features w3m as an HTML previewer:

text/html w3m -T text/html -dump %pistol-filename%

And here’s an example that leverages ls for printing directories’ contents:

inode/directory ls -l --color %pistol-filename%

Matching File Path

For example, say you wish to preview all files that reside in a certain ./bin directory with bat’s syntax highlighting for bash. You could use:

fpath /var/src/my-bash-project/bin/[^/]+$ bat --map-syntax :bash --paging=never --color=always %pistol-filename%

A Note on RegEx matching

When Pistol parses your configuration file, as soon as it finds a match be it a file path match or a mime type match, it stops parsing it and it invokes the command written on the rest of the line. Therefor, if you wish to use the examples from above which use w3m and bat, you’ll need to put w3m’s line before bat’s line. Since otherwise, text/* will be matched first and text/html won’t be checked at all.

Similarly, you’d probably want to put fpath lines at the top.

Of course that this is a mere example, the same may apply to any regular expressions you’d choose to match against.

For a list of the internal regular expressions tested against when Pistol reverts to its native previewers, read the file internal_writers/map.go.

More examples can be found in this WiKi page.

Quoting and Shell Piping

Pistol is pretty dumb when it parses your config, it splits all line by spaces, meaning that e.g:

application/json jq '.' %pistol-filename%

This will result in an error by jq:

jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
'.'
jq: 1 compile error

Indicating that jq got a literal '.'. When you run in your shell jq '.' file.json you don’t get an error because your shell is stripping the quotes around .. However, Pistol is not smarter then your shell because if you’d try for example:

application/json jq '.[] | .' %pistol-filename%

That would be equivalent to running in the typical shell:

jq "\'.[]" "|" ".'" file.json

That’s because Pistol doesn’t consider your quotes as interesting instructions, it just splits words by spaces. Hence, to overcome this disability, you can use:

application/json sh: jq '.' %pistol-filename%

Thanks to the sh: keyword at the beginning of the command’s definition, the rest of the line goes straight as a single argument to sh -c.

You can worry not about quoting / escaping the rest of the line - it’s not like when you run e.g sh -c 'command' in your shell where you need to make sure single quotes are escaped or not used at all inside command.

More over, with sh: you can use shell pipes:

fpath .*.md$ sh: bat --paging=never --color=always %pistol-filename% | head -8

Passing arbitrary extra arguments to commands

Pistol is capable of passing extra arguments to commands if the config says so. The arguments %pistol-extra0%, %pistol-extra1% and so on, are substituted by the extra arguments given to pistol, if these present in invocation and if they are present in the config. Example usage:

With this config:

fpath /problematic-bz2/.*.bz2 bzip2 %pistol-filename% %pistol-extra0%
fpath /working-bz2/.*.bz2     bzip2 %pistol-filename%

Running:

pistol /problematic-bz2/example.bz2 --test

Will run bzip2 while testing the integrity of the compressed file. However, running:

pistol /working-bz2/example.bz2 --test

Will not pass the --test argument to bzip, due to %pistol-extra0 not present in the config for the files at /working-bz2. This feature is mainly present for usage with Lf and Ranger which can pass width height and x, y coordinates for image previews.

Here’s an example usage for image previews that works with Lf: [4]

image/.* pv %pistol-filename% %pistol-extra0% %pistol-extra1% %pistol-extra2% %pistol-extra3%

Environmental Variables

Pistol’s internal previewer for text files includes syntax highlighting thanks to the Go library chroma. You can customize Pistol’s syntax highlighting formatting and style through environmental variables.

Chroma Formatters

The term formatter refers to the way the given file is presented in the terminal. These include:

  • terminal: The default formatter that uses terminal control codes to change colors between every key word. This formatter has 8 colors and it’s the default.

  • terminal256: Same as terminal but with 256 colors available.

  • terminal16m: Same as terminal but with 24 Bits colors i.e True-Color.

Other formatters include json, and html but I’d be surprised if you’ll find them useful for Pistol’s purpose.

To tell Pistol to use a specific formatter, set PISTOL_CHROMA_FORMATTER in your environment, e.g:

export PISTOL_CHROMA_FORMATTER=terminal16m

Recent versions of Lf support 256 colors in its preview window. AFAIK, [5], Ranger supports 8 colors and Lf’s color256 isn’t enabled by default.

Therefor, I decided that it’ll be best to keep this variable unset in your general environment. If you do set color256 in your lfrc, you may feel free to set PISTOL_CHROMA_FORMATTER in your environment.

Chroma Styles

The term style refers to the set of colors used to print a given file. The chroma project documents all styles here and here.

The default style used by Pistol is pygments. To tell Pistol to use a specific style set PISTOL_CHROMA_STYLE in your environment, e.g:

export PISTOL_CHROMA_STYLE=monokai

Debugging

Can’t figure out way does Pistol acts the way he does? You can run pistol with:

env PISTOL_DEBUG=1 pistol test-file

And you should be able to see messages that may give you a clue.

NEWS


1. Considering Pistol’s indirect dependence on libmagic(3), I will never take the trouble to personally try and make it work on Windows natively. If you’ll succeed in the heroic task of compiling libmagic for Windows and teach magicmime to use it, please let me know.
3. env GO111MODULE=on is needed due to a recent bug / issue with Go, see #6 for more details. CGO_ENABLED=1 is needed for magicmime, see #76.
4. pv script refers to this script.
5. I don’t use Ranger anymore, ever since I moved to Lf. If you have evidence it does support 256 colors, let me know and I’ll change the default.

pistol's People

Contributors

doronbehar avatar duganchen avatar lucas-mior avatar renovate[bot] avatar seasonedfish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

pistol's Issues

cleaner

hello there.

lf has a cleaner options for previews, which is meant to be used after using ueberzug to display an image.
It will clear the screen when the user selects the next file so that the terminal can show up whatever next preview.

However, the problem with this approach is that everytime an image comes after the other, the cleaner will be unnecessarly called,
since all image previews shall return an error (which is a signal to lf to call the cleaner). This causes an annoying flickering between images, as noted in this issue. Ueberzug replaces one image for the other very smoothly when the cleaner isn't executed.

In the aforementioned issue, the user suggests to allow control over the cleaner, but I think the better solution is for the preview program to clean the screen (if necessary). Maybe pistol could have an cleaner option, like lf, but also another option which sets which file types require that the previous one is cleared. The advantage is that other programs using pistol, like fzf, don't require to deal with this issue. The solution is within the previewer.

I could write a PR if it is possible to be accepted.
Cheers!

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

gomod
go.mod
  • go 1.20
  • github.com/adrg/xdg v0.4.0
  • github.com/alecthomas/chroma/v2 v2.14.0
  • github.com/alessio/shellescape v1.4.2
  • github.com/alexflint/go-arg v1.5.0
  • github.com/doronbehar/magicmime v0.1.1-0.20211127135329-3de4ff29dc49@3de4ff29dc49
  • github.com/dustin/go-humanize v1.0.1
  • github.com/mholt/archiver/v3 v3.5.1
  • github.com/nwaples/rardecode v1.1.3
  • github.com/sirupsen/logrus v1.9.3

  • Check this box to trigger a request for Renovate to run again on this repository

pistol.conf could be better

I noticed that parsing of pistol.conf fails when there is more than one space between the mime type and preview program.
Which makes the config file really messy.

Piping is not working

Hi,
Piping in preview commands does not work. Is it the behaviour it should have?

This is working:

column -s, -t < %s

But this is not (Outputs nothing):

column -s, -t < %s | head

And this is working:

rar lb %s

This is not (Outputs nothing):

rar lb %s | sort

Pistol version: 0.0.2.r15.gbd918ca-1
I am using lf and also tried previewing with pistol executable in shell.

Thanks :)

can't install using go in m1 mac

          > 

I tried this on my m1 mac and didn't work for me..please anyone can help to fix this?

CGO_CFLAGS="-I/opt/homebrew/Cellar/libmagic/5.44/include/magic.h" go install github.com/doronbehar/pistol/cmd/pistol@latest
# github.com/doronbehar/magicmime
go/pkg/mod/github.com/doronbehar/[email protected]/magicmime.go:28:11: fatal error: 'magic.h' file not found
 #include <magic.h>
          ^~~~~~~~~
1 error generated.

Originally posted by @kavindalj in #6 (comment)

GitHub release for ARM64/`aarch64` binary

Currently GitHub Release only has single binary for amd64 architecture. I prefer to download binary from there so I don't need to compile/build it myself.

But I can't use this in my raspberryPI with the aarch64 architecture. Does this tool can be build on aarch64? If so, please make automated build for aarch64 as well and released on GitHub Release.

Thank you very much 🙏

Documenting the way of parsing the quotes

I have encountered some quoting issues. But I've noticed that they are features of
Go that may be documented.

For example I am using jq for previewing json files.
jq needs a query string with a quote like '' or '.' for the whole json.

jq '.' file.json

This is not working in pistol. When executed, jq gives an error:

jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <top-level>, line 1:
'.'
jq: 1 compile error

jq says it got '.' instead of .. Go parser escapes the quotes. But in the
shell, quotes are consumed. So in pistol we should do:

application/json jq . %s

or with the upcoming sh: feature:

application/json sh: jq '.' %s

I think this should be documented to direct people to use sh: feature or
handle the quotes with this way.

Enable to configure archive columns (all besides the file name)

In #61, I discussed a bit the idea of configurable archive columns. Here's a more accurate proposal:

Make it possible to specify archive files output format, where the file name always appears at the end. The filename should always appear at the end, since their length could be too long for us to predict in advance. We don't want to make pistol read beforehand the file names and decide on the padding such that it will print nicely.

The columns to be printed will be decided by parsing an environment variable with comma-separated values, in which order matters, and is reflected in the output.

Perhaps an additional environment variable, or using a more sophisticated parsing of the above env var, will specify what columns should have lower and higher priority. The low priority columns will not get printed if the output terminal window has too low number of columns.

%pistol-extra% substitution not working.

I just tried the new functionally for image previewing discovered a small issue.

image/* chafa -s %pistol-extra0%x%pistol-extra1% %pistol-filename%

does not work it produces nothing for %pistol-extra0%x%pistol-extra1% but if i add some spaces:
%pistol-extra0% x %pistol-extra1% it produces the expected output eg. 10 x 20.

configuration file path doesn't corespond to README

In the README is a statement that pistol reads configuration from this path: ~/.config/pistol/pistol.conf

However what it actually reads is ~/.config/pistol.conf to be easily demonstrated:

asmar:~/go/bin$ strace ./pistol ~/Documents/Daily.pdf 2>&1 | grep conf
newfstatat(AT_FDCWD, "/home/asmar/.config/pistol.conf", 0xc00013a9f8, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/etc/xdg/xdg-ubuntu/pistol.conf", 0xc00013aac8, 0) = -1 ENOENT (No such file or directory)
newfstatat(AT_FDCWD, "/etc/xdg/pistol.conf", 0xc00013ab98, 0) = -1 ENOENT (No such file or directory)

Moving from ~/.config/pistol/pistol.conf to ~/.config/pistol.conf works and pistol now reads configuration.

Configuration specificity seems backwards

$ cat ~/.config/pistol/pistol.conf
text/* bat -p --paging=never --color=always %s
text/html w3m -T text/html -dump %s

would preview html files with bat.

$ cat ~/.config/pistol/pistol.conf
text/html w3m -T text/html -dump %s
text/* bat -p --paging=never --color=always %s

would preview html files with w3m.

I would expect the former to work (i.e., preview with w3m), and configuration defined later in the file to override configuration from earlier in the file.

local chroma styles

I automatically trigger a script when I change the my terminal's configuration. This way I can toggle a dark of light theme by exporting $PISTOL_CHROMA_STYLE.

However, I'd like to preview with the same colorscheme as in vim, and I'm unable to find a style that fits my criteria:

  • does not set background colors (e.g. text against semi-transparent terminal background)
  • has a readable dark and a light variant
  • was shared in other formats by users of other programs (vim and it's plugins in particular)

Nikyle Nguyen's papercolor-theme has been made available for a variety of programs. Should I try to add one to the styles over at the chroma/pygments repository, or could you adapt a mechanism for including a local file? This would make testing easier.

man page

If you have interest, I could write a man page for pistol.

pass arguments forward

Hey, since lf now can pass width, height, x, y of the preview pane (gokcehan/lf#531)
to the previewer, it would be very nice if pistol actually did something with them (mainly passing them to the programs pistol is calling).

Thanks.

pistol not print JSON data

What is the thinking behind not print JSON data and instead displaying a message stating that it is JSON data?

Standardize version updates

env GO111MODULE=on go get -u github.com/doronbehar/pistol/cmd/pistol
go: found github.com/doronbehar/pistol/cmd/pistol in github.com/doronbehar/pistol v0.0.4
go: github.com/klauspost/pgzip upgrade => v1.2.3
go: github.com/galdor/go-cmdline upgrade => v1.1.1
go: github.com/adrg/xdg upgrade => v0.2.1
go: github.com/klauspost/compress upgrade => v1.10.4
go: github.com/dlclark/regexp2 upgrade => v1.2.0
go: github.com/sirupsen/logrus upgrade => v1.5.0
go: golang.org/x/sys upgrade => v0.0.0-20200409092240-59c9f1ba88fa
go: github.com/konsorten/go-windows-terminal-sequences upgrade => v1.0.2
go: github.com/andybalholm/brotli upgrade => v1.0.0
go: github.com/pierrec/lz4 upgrade => v2.5.0+incompatible
go: github.com/golang/snappy upgrade => v0.0.1
go: github.com/nwaples/rardecode upgrade => v1.1.0
go: github.com/ulikunitz/xz upgrade => v0.5.7

and
~/C/g/bin ❯❯❯ $GOBIN/pistol --version
v0.0.3 (2019-12-13)

Request: prebuilt binaries released on github

First of all thank you for your work in this project, such a usefull thing to use with ranger.

I already read that you wrote:

TBH, personally I don't have any motive to create packages of Pistol for any distro, not even my own (NixOS). As a developer of this program, I just install it to $GOPATH/bin/ and this is how I continuously test it while changing it.

But have you thought how usefull ranger and pistol are on tiny less powerfull computers , SBC boards etc, on ARM architecture. ?
Think of Raspberrry Pi and alike. It's not practical, for non developers/programmers to constantly download and redownload again and again the entire Go chain infrastructure and build on them constantly.

It also eases the work of distro package maintainers, who want to provide an easy to install package. Example, in AUR, Archlinux, in addition to a package called "pistol-git" that already exists, one could provide and additinial "pistol-bin" package, that just pulls from the github repo the released bin. That's how so many Go projects are package in Archlinux do it.

I also know it can be cumbersome to support "all" of arm architectures . But usually all it takes is one single arm for 32 bit that runs on all arm5, 6, 7 and and another for arm64. Go projects 99% of the time run wonderfully on all them.

So many other (go) projects do this. Are you aware of github actions/workflows, goreleaser etc. and all the no cost ways to automate this ?

See one of many examples, https://github.com/tsl0922/ttyd/tree/master/.github

Or even lf , with so many different plattforms, https://github.com/gokcehan/lf/releases that uses travis,
https://github.com/gokcehan/lf/blob/master/.travis.yml
No end user would even want to try lf instead of ranger on a raspberry pi, if you had to download 500 mega of go just to compile it.

It's really a pitty missing this and the real power of Go being such an universal and easy to distribute to different architectures.

Thanks in advance

Design suggestion for speed and simplicity

Continuing from gokcehan/lf#161

My current plan for the handle function is as follows:

After the mime type is known, while reading the configuration file, if a mime type in it matches (with regex) to our mime type, we stop reading the rest of the configuration file and we continue to processing the command. This way, if a mime type has additional matchers in the configuration file, the first will take precedence and users will need to be aware of that.

Help with sh:

I can't make the following work:

audio/* sh: mediainfo "%s" | awk -F' {2,19}:' '{printf("%s : %s\n",$1,$2)}'

The code works in zsh. I've tried changing awk's quoting to double quotes and escaping quotes and dollar signs, but any of that did.
What I am missing?

Install Fails

Unable to install using go get. It appears there is a dependency issue.

~/.config/lf  brew install libmagic
==> Downloading https://homebrew.bintray.com/bottles/libmagic-5.37.high_sierra.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/14/14eb5417f36b7ae1813a290c6004c880bd2c50498bc470a48dd9fb8cb489aa4e?__gda__=exp=1574840839~hmac=ea3c38b75d874c38c4341e6
######################################################################## 100.0%
==> Pouring libmagic-5.37.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/libmagic/5.37: 315 files, 6.7MB
~/.config/lf  go get -u github.com/doronbehar/pistol/cmd/pistol
package github.com/pierrec/lz4/v3: cannot find package "github.com/pierrec/lz4/v3" in any of:
	/usr/local/Cellar/go/1.13.4/libexec/src/github.com/pierrec/lz4/v3 (from $GOROOT)
	/Users/brandon/go/src/github.com/pierrec/lz4/v3 (from $GOPATH)

Missing License

I just realized there is no license in repo, this makes pistol All Rights Reserved project...

Could you add some license? 😄

Fork rakyll/magicmime to add openbsd support and perhaps support cross compilation.

When I attempted to install pistol, which I am totally stoked about, I received an error concerning build constraints. Never seen this one before, and I suspect it is an unintended error.

# Command Exec
$ env GO111MODULE=on go get -u github.com/doronbehar/pistol/cmd/pistol 
# Output recieved
package github.com/doronbehar/pistol/cmd/pistol
	imports github.com/doronbehar/pistol
	imports github.com/rakyll/magicmime: build constraints exclude all Go files in $HOME/go/bin/pkg/mod/github.com/rakyll/[email protected]

To me at least, it seems odd that all Go files are excluded. Any suggestions would be nice... this is a weird one.

pistol panics when pistol.conf is empty

Hey I noticed that when pistol.conf is empty with only whitespace pistol panics. It appears to be a out of bounds error on line 66 of previewer.go because of the splitting on spaces.

I don't know any Go, but I guess you could strip the leading and trailing space before the string splitting if you care to fix this:

On Line 60: def := strings.Split(strings.TrimSpace(scanner.Text()), " ")

pistol.conf isn't loaded on OS X

I'm wondering if this is the issue behind this one:

#19

I've noticed that on OS X, ~/.config/pistol/pistol.conf isn't loaded.

I have the following in ~/.config/pistol/pistol.conf:

image/* viu %pistol-filename%

If I just run pistol against a image, the setting doesn't take effect:

▶ pistol Lohse-3840x2160.jpg
JPEG image data, Exif standard: [TIFF image data, little-endian, direntries=0], baseline, precision 8, 3840x2160, components 3

(That's Divinity: Original Sin 2 wallpaper, if you're wondering).

But if I force it to load pistol.conf,

▶ pistol -c ~/.config/pistol/pistol.conf Lohse-3840x2160.jpg

Then I see the image in the terminal.

Is WSL support possible for images

Hi, thanks for all the great work from any and all contributors.

I was trying it out on WSL2 Ubuntu 22 and image preview does not seem to work. The archive and other files are working. Is this a WSL terminal limitation? If anyone knows. Thanks in advance.

Add make variables for Mac OS 12.5/ARM

Env:

go version go1.19 darwin/arm64
OS: macOS Monterey 12.5

I've previously installed Pistol on OS 11.6/Intel with no issues, but on a new machine I'm unable to install or build it.

Steps:

$ brew install libmagic
...
(installation succeeds)

$ brew link libmagic
Already linked: /opt/homebrew/Cellar/libmagic/5.42

$ go install github.com/doronbehar/pistol/cmd/[email protected]
../../go/pkg/mod/github.com/doronbehar/[email protected]/magicmime.go:28:11: fatal error: 'magic.h' file not found

$ CGO_CFLAGS="-I${HOMEBREW_PREFIX}/Cellar/libmagic/5.42/include" go install github.com/doronbehar/pistol/cmd/[email protected]
/opt/homebrew/Cellar/go/1.19/libexec/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
ld: library not found for -lmagic
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I get the last error (ld: library not found for -lmagic) when attempting to build from source, as well.

I'm mostly posting this in case other OS X users run into it -- the problem seems to be with libmagic, and I suspect you're unable to help troubleshoot OS X anyway :)

Pistol is now supported on nnn

This file previewer is now supported on nnn by using the preview-tui plugin. It's a fairly popular file manager, I just wanted to mention this in case you wanted to update the docs on how it can be integrated.

All you have to do is install nnn, download and enable the plugin by setting NNN_PLUG accordingly, and most importantly, set USE_PISTOL=1, either in the preview-tui script, or as an environment variable. NNN_FIFO is necessary, but it can be replaced by nnn -a. The script can be launched automatically with nnn -P k where k is the assigned key from NNN_PLUG. The wiki has tons of details on how to configure nnn properly, but if you need my help do tell. I can even do it in a PR if you want, or review yours.

Cheers!

Bug: + symbol in mimetype

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.

Bump Chroma

There is some new styles in chroma 0.9.1 I would like to use. Also a release with #59 would be nice (with an associated nixpkgs bump I could remove a lot of overlays). 🙇

Image preview does not work with TUI file managers.

I am using Pistol to preview files in Lf but for some reason, it does not work with images, it only shows a blank preview window. In Ranger I use the default previewer script with previewer_image_method set to kitty. That works fine but when I switch to Pistol, the preview brakes. I am trying to add image previews to Lf like they are in Ranger, but it does not work. Calling Pistol from terminal with an image argument causes it to display the image without issues. In the pistol.conf file, I have set image/* kitty +kitten icat %s. It however, does not work in Lf or Ranger. I am using Kitty terminal. I have tried this on Alacritty, ST-manjaro and xfce4-terminal. Same results.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Support statically linking

The only non Go dependency of pistol is file for mime type detection. Building a static executable with all the magic database in it will be thrilling, as it'd allow distributing this program using GitHub's releases assets. Doing so via Nix would be even better.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.