0

In mc (midnight commander), I can define custom command for viewing files, ie:

shell/i/.jpg
    Open=gpicview %f 
    View=file %f | less

The command file %f has to be piped to a pager. I am using here less as example.

The problem with less is, it displays the one line in the middle of the screen, and adds these characters:

~
~
(END)

I just need the simplest, stupidest possible pager that does nothing other than display what it receives from pipe redirection. Something like the cat command, which does not add anything to a file that it is displaying.

What can I use instead of less ?

Or can I configure less to hide those special characters?

UPDATE:

OK, I have fixed some of the problems in less by using the options --tilde and --clear-screen. However, less still shows (END) at the bottom of the page.

Can I get rid of the (END) ? If there is no configuration option for that, how could I change it in the sourcecode (I am OK with recompiling less package)

I am using less on Debian 10. less --version shows:

less 487 (GNU regular expressions)
18
  • 1
    Why do you need a pager and why can't you use cat if it fits your need? Sep 16, 2022 at 7:02
  • @Stéphane Chazelas - when I use View=file %f | cat in mc.ext, it does not work. Nothing happens. Sep 16, 2022 at 7:12
  • It probably does work but there's nothing holding the result on screen for long enough for you to see it
    – roaima
    Sep 16, 2022 at 7:19
  • 1
    Did you give a chance to good old pg (deprecated but still included in the util-linux pack)
    – MC68020
    Sep 16, 2022 at 7:28
  • 1
    clear; file %f; read Use {Enter} to quit
    – roaima
    Sep 16, 2022 at 8:14

1 Answer 1

1

mc has its own internal pager/viewer, no need to invoke a separate one, you just need:

type/^JPEG
  View=%view file -- %p

(here based on file type (regexp applied to the output of file) rather than file name)

See the comments at the top of the default mc.ext for documentation.

The default viewer for JPEG files is actually defined as:

type/^JPEG
        View=%view{ascii} /usr/lib/mc/ext.d/image.sh view jpeg
        Include=image
[...]
include/image
        Open=/usr/lib/mc/ext.d/image.sh open ALL_FORMATS
        View=%view{ascii} /usr/lib/mc/ext.d/image.sh view ALL_FORMATS

Having said that, less has:

-~ or --tilde
Normally lines after end of file are displayed as a single tilde (~). This option causes lines after end of file to be displayed as blank lines.

And the prompt string can be defined with -Ps'prompt'. To remove it, including the (END) at the end, you can pass -Ps alone, though you'll still see a :. With -Ps$'\r' (or -Ps"$(printf '\r')" for shells that don't support the $'...' quotes from ksh93), that : goes as well.

So:

type/^JPEG
  View=file -- %p | less -~ -Ps"$(printf '\r')"

If you want something that clears the screen, runs the file command with its output untouched and then waits for some key press to exit, you could just do:

type/^JPEG
  View=zsh -c 'echoti clear; echoti civis; file -- "$1"; read -sk; echoti cnorm; echoti clear' zsh %p

(here also hiding the cursor with echoti civis as a bonus).

Instead of staying on the main screen and clearing it upon entry and exit, you could also switch back to the alternate screen (the one normally used by mc) as less does without -X so as to leave the main screen untouched:

type/^JPEG
  View=zsh -c 'echoti smcup; echoti home; echoti civis; file -- "$1"; read -sk; echoti cnorm; echoti rmcup' zsh %p

(here not bothering clearing it as mc will take care of it).

3
  • the --tilde option works to remove the ~, but how do I get rid of the (END) at the bottom of the page? (and I know mc has its own internal viewer, but it tries to be too fancy. I need to only display the data, without menus, and headers, and so on) Sep 16, 2022 at 12:50
  • less -E will cause less to terminate when it reaches the end of the file rather than displaying the visual EOF marker (END).
    – DopeGhoti
    Sep 22, 2022 at 5:07
  • 1
    @DopeGhoti, but that would still exit less straight away if the output fits in one screen which means the user won't get time to see it. -Ps would remove that (END). Sep 22, 2022 at 6:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .