3

When I'm logged in to a remote machine in eshell I can still do man ls. But it appears that this only work for my local man pages. If I try man yum I'll get a message that the yum man page is not found. However, if I log into the machine via a regular terminal and use man yum there the manual is shown. Is there a way to get remote man pages showing up when in TRAMP mode? I'd really like that because I'm running OS X locally but frequently log in to linux servers where the utilities have different options etc.

Update: To clarify, here's an example session:

Welcome to the Emacs shell
~ $ cd /ssh:example.com:/
/ssh:example.com:/ $ man yum
#<buffer *Man yum*>

Alright! That's expected. But, regretfully, no *Man yum* buffer is created an these messages appear in *Messages*:

Invoking man yum in the background
Please wait: formatting the yum man page...
yum man page formatted
error in process sentinel: user-error: Can't find the yum manpage
error in process sentinel: Can't find the yum manpage

Update 2: I found out (from a comment on this answer) that I can invoke the remote man by prefixing with *, so *man yum -- which is an OK work-around. But it just dumps the content in the eshell window, rather than open a new buffer like the man command does. I'd really like that behaviour.

5
  • Do you mean man as the emacs command, or as the shell command?
    – choroba
    Commented Feb 23, 2016 at 17:46
  • I mean when typing man yum in eshell, the emacs shell. Not M-x man. Commented Feb 23, 2016 at 18:05
  • That's the same, because eshell runs in emacs. Try \man yum instead.
    – choroba
    Commented Feb 23, 2016 at 18:09
  • 1
    \man yum does not work, but *man yum kinda does -- I've added my "objection" to that to the question also. Commented Feb 23, 2016 at 18:14
  • 1
    See also this question on Stack Overflow.
    – legoscia
    Commented Feb 24, 2016 at 18:49

1 Answer 1

5

I have found a work-around! Admittedly it is a bit hacky, and uses woman rather than man, but I think this might just work for me. Essentially, woman-find-file is tramp aware, so if we can pass it the path to the remote man page it will open it just fine.

Passing the --path flag to man will output the path of the manpage rather than open the manpage itself. Woman doesn't like pre-formatted man pages, so pass the -c flag to ignore those. Now we can execute the remote man command (by prefixing man with *) to find the path to the foo man page thus: *man -c --path foo.

The following function takes a path from the above and checks if it is a remote path. If it is, it prepends the tramp method, user & host to the local file name. Then it invokes the woman-find-file function on the result. Put it in your ~/.emacs.d/init.el.

(defun tramp-aware-woman (man-page-path)
  (interactive)
  (let ((dir (eshell/pwd)))
    (woman-find-file
     (if (file-remote-p dir)
         (let ((vec (tramp-dissect-file-name dir)))
           (tramp-make-tramp-file-name
            (tramp-file-name-method vec)
            (tramp-file-name-user vec)
            (tramp-file-name-host vec)
            man-page-path))
       man-page-path))))

Now we can create an alias that invokes our function for a bit of ux sugar:

alias man 'tramp-aware-woman ${*man -c --path $1}'

The new command should work from eshell both locally and remote, though you will now get woman's rendering. You may want to choose a different name for the alias if you want to retain the existing behaviour of man for local man pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.