[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ranger-users] previewing a certain file type with external utility

From: Thoralf Dassler
Subject: Re: [Ranger-users] previewing a certain file type with external utility (tricky case?)
Date: Sun, 15 Jul 2018 23:59:02 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

On 14.07.18 08:58, Dimitrios Semitsoglou-Tsiapos wrote:
On 14/07/18 02:08, Thoralf Dassler wrote:
Hi all,

trying to configure ranger for the first time. I have a bunch of
files, for which ranger tells me:

---File Type Classification---
SMTP mail, ASCII text


---File Type Classification---
SMTP mail, ASCII text, with very long lines

The file name of these is just an integer number, N (1, 2, 3, 4,
..., 219, ...), without a file extension.

On the command line (not running ranger) I use a utility, which
takes N as an argument: 'show N'. This displays the content of
N in a formatted way ('formatted' means: only display
certain parts of the file contents, and filter out other parts).

I'd like ranger to use 'show N' as auto-preview for these files.
I suspect I'd have to do four things within ranger's config

1) have a condition for 'SMTP mail ASCII text' (with or without
very long lines)
2) while running ranger: for the condition, pick N to which I
3) pass N as an argument to 'show'
4) make ranger do 'show N'

Hope someone can help.

Many thanks,


Conveniently, ranger comes with a tool for doing file previews called
`scope`, which in turn uses the configuration file at
`~/.config/ranger/scope.sh`. Use `ranger --copy-config=scope` if you
don't have that file yet.

In that file you will notice that scope can figure out how to handle a
file either by looking at its extension or its mimetype. Since your
files have no extension, you most likely want to use mimetypes. To
figure out the mimetype of your file, do `mimetype N` on one of your
files. You will probably get `message/rfc822`, meaning you would add
something like the following in the mimetype case:

       try my_show_program "$path" && { dump | trim; exit 0; }

Also take a look at `~/.config/ranger/rifle.conf` for opening (as
opposed to previewing) files.

Good luck,


thanks for the quick response. Going with Dimitri's suggestion, I have added this section to my ~/.config/ranger/scope.sh:

# Mail
show "${FILE_PATH}" && { dump | trim; exit 0; }

${FILE_PATH} is defined in scope.sh as
FILE_PATH="${1}"         # Full path of the highlighted file

In my case ranger should therefore run:
'show /home/user/mail/inbox/N' (N is an integer number, it
represents the file names in /home/user/mail/inbox)

However, what I actually need is: 'show $N', i.e.: I need to
only pass the file names without the path.

Can '$N' be done in scope.sh? If yes, how would I have to do it?

Explanation: The reason why I need only '$N' is because
1) The utility 'show' insists on its dedicated .mh_profile being present;
2) 'Path:' must be defined within .mh_profile. The value of
'Path:' therefore gets auto-inserted in front of '${FILE_PATH}', which does not work of course. Hence I only need '$N'.

Many thanks,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]