2

Basically I want to run watch from eshell.

Simply running watch date (for example) doesn't work (only the first header line is displayed). Apparently I should run it with term or ansi-term but these two commands take only one argument -the command, which would be watch - and I don't know where to put the arguments (i.e. date in the example above).

So, I guess my question is: What is the proper way to run watch date (or any other watch such as watch "make myprog && ./myprog") from eshell?

2

Interesting question. I found a non-trivial answer. Looking at functions term and ansi-term, I saw that though they themselves only take one program-related argument, under the hood they both invoke functions that allow passing additional arguments to programs (make-term and term-ansi-make-term respectively). This gave me an idea about how to accomplish what you want:

  • for term: (switch-to-buffer (make-term "test-term" "/bin/bash" nil "-c" "watch date"))
  • for ansi-term: (switch-to-buffer (term-ansi-make-term "test-ansi" "/bin/bash" nil "-c" "watch date"))

It's a bit unwieldy in that form, so you might want to write a function abstracting this:

(defun eshell/watch-process (process)
     (switch-to-buffer
      (term-ansi-make-term "test-ansi" "/bin/bash"
                   nil "-c" (format "watch %s" process))))

And then you can run watch-process date directly in Eshell.

2

The Eshell documentation refers to commands that are not line-oriented but are designed to run in a terminal, such as watch, as "visual commands". To tell Eshell that a command is a visual command, add its name to the list in the eshell-visual-commands variable as follows:

(push "watch" eshell-visual-commands)

Thenceforth Eshell will automatically run watch in a term buffer.

See Input/Output in the Eshell manual.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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