Package: mime-support Version: 3.54 Severity: wishlist Tags: patch File: /usr/bin/run-mailcap
If you elevate the vim entry in /usr/lib/mime/packages/vim-common in ~/.mailcap so that it is used, text/plain; view %s; edit=vim %s; compose=vim %s; test=test -x /usr/bin/vim; needsterminal; priority=4 and with /usr/bin/view alternative pointing to vim, then running cat /etc/passwd | see text/plain:- gives a warning from vim Vim: Warning: Input is not from a terminal and on exiting with :q vim leaves the terminal in raw mode. I hoped that run-mailcap would redirect stdin to the tty when a mailcap entry says needsterminal, ensuring the program is run with both stdin and stdout as the tty. I get some joy from the change below.
--- run-mailcap.orig 2013-05-11 23:17:57.000000000 +1000 +++ run-mailcap 2013-10-23 11:43:47.000000000 +1100 @@ -431,6 +431,7 @@ my $done=0; my $fail=0; + my $needsterminal; foreach $match (@matches) { my $comm; print STDERR " - checking mailcap entry \"$match\"\n" if $debug; @@ -449,14 +450,20 @@ } my($tmpfile,$tmplink); - if ($action ne 'print' && $match =~ m/;\s*needsterminal\s*($|;)/ && ! -t STDOUT) { - if ($ENV{DISPLAY}) { - $comm = "$xtermprgrm -T '$file ($type)' -e $0 --action=$action '${type}:%s'"; + if ($action ne 'print' && $match =~ m/;\s*needsterminal\s*($|;)/) { + $needsterminal = 1; + if (-t STDOUT) { + print STDERR " - needsterminal is satisfied by stdout\n" if $debug; } else { - print STDERR " - no terminal available for rule (needsterminal)\n" if $debug; - $fail++; - next; + if ($ENV{DISPLAY}) { + $comm = "$xtermprgrm -T '$file ($type)' -e $0 --action=$action '${type}:%s'"; + } else { + print STDERR " - no terminal available for rule (needsterminal)\n" if $debug; + $fail++; + next; + } } + } elsif ($action eq 'view' && !$nopager && $match =~ m/;\s*copiousoutput\s*($|;)/ && $type ne 'text/plain') { $comm .= " | $0 --action=$action text/plain:-"; } @@ -509,6 +516,25 @@ if ($comm =~ m/[^%]%s/) { $tmpfile = SaveStdin($match); $comm =~ s/([^%])%s/$1$tmpfile/g; + + # If needsterminal then redirect stdin to the tty which is + # on stdout, rather than leaving it as the input data stream + # which has now been read through to EOF. + # + # Some programs such as "more" and "less" already use + # /dev/tty rather than stdin. But "vim" on non-tty stdin + # gives a warning message and then leaves the tty in raw + # mode on exit. Or "nvi" refuses to run at all unless both + # stdin and stdout are the tty. + # + # RFC 1524 is silent on exactly what a program with + # "needsterminal" should expect, but it seems sensible to + # arrange that both stdin and stdout are the terminal for + # "needsterminal" with "%s". + # + if ($needsterminal) { + $comm .= ' <&1'; + } } else { # no name means same as "-"... read from stdin }
-- System Information: Debian Release: jessie/sid APT prefers unstable APT policy: (990, 'unstable') Architecture: i386 (i686) Kernel: Linux 2.6.32-5-686 (SMP w/1 CPU core) Locale: LANG=en_AU, LC_CTYPE=en_AU (charmap=ISO-8859-1) Shell: /bin/sh linked to /bin/dash mime-support depends on no packages. Versions of packages mime-support recommends: ii file 1:5.14-2 mime-support suggests no packages. -- no debconf information