help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Shell aliases as shell-commands


From: Michael Heerdegen
Subject: Re: Shell aliases as shell-commands
Date: Thu, 22 Jan 2009 18:55:54 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (berkeley-unix)

Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:

> Michael Heerdegen <michael_heerdegen@web.de> writes:
>
> Just want to mention (again) that eshell-command work out of the box for
> aliases. No config is needed. 
> The aliases are stored by default in .emacs.d/.eshell and are
> different of those you have in .bashrc, that is a good thing:
> You may have alias in your bashrc that are good for interactive shell
> but no good for non-interactive shells.
> And that avoid modifying bash with shopt (strange things can happen)
>
> And you have file-name completion also.
> To add an alias:
> M-x eshell-command
> alias Mcle mount /dev/sdb1
>

Yes, and eshell-command even completes these aliases!

I have a question: Is it possible to run something asynchronously with
M-x eshell-command? I wrote some code providing a menu from which you
can start external programs (browsers, games and such stuff) like most
window managers have, from Emacs. It is based on shell-command. It
would be nice if it could use eshell-command instead. The menu itself
uses a command I called `run-external-command'


(defun run-external-command (command)
  "Prompt for an external command and run it asynchronously.
It combines `read-shell-command' (which provides completion)
and `asynchronous-shell-command'."
  (interactive
   (list
    (funcall
     (if (fboundp 'read-shell-command)
      'read-shell-command
       'read-string)
     "Run external application: ")))
  (let ((default-directory "~/"))
    (asynchronous-shell-command command command)))

(global-set-key [?\C-c ?e] 'run-external-command)

(defun asynchronous-shell-command
  (command buffer-name)
  "Execute COMMAND asynchronously in an inferior shell.
The corresponding asynchronous Emacs process is associated with a
\(unique\) buffer with a name based on the string BUFFER-NAME."
  (let*
      ((buffer-name
        (if
            (stringp buffer-name)
            (generate-new-buffer-name
             (concat "ASC: " buffer-name))
          "Asynchronous shell command"))
       (b (get-buffer-create buffer-name))
       (pop-up-frames nil))
    (save-window-excursion
      (let
          ((call
            (concat "(" command ") &")
            ;; (command) & should be understood by all common
            ;; shells
            ))
        (shell-command call b)
        (with-current-buffer b
          (save-excursion
            (goto-char (point-max))
            (insert "\n\n"
                    (make-string fill-column ?-)
                    "\n\nProcessed command: "
                    call)))
        (message "%s" call)
        (when b
          (with-current-buffer b
            (make-local-variable 'asynchronous-shell-command-buffer)
            (setq asynchronous-shell-command-buffer t)))))))


 Is it possible to get this work with `eshell-command'?


reply via email to

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