[Top][All Lists]

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

Re: Interactive shell commands

From: Sebastian Tennant
Subject: Re: Interactive shell commands
Date: Tue, 20 Jan 2009 21:59:36 +0000
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux)


Just realised that I forgot to rename the sentinel function so that it
doesn't break the standard function; shell-command.

Please use this code, not that included in my previous post.



;;; sentinel for asynchronous commands
(defun interactive-shell-command-sentinel (process signal)
  (if (memq (process-status process) '(exit signal))
      (message "%s: %s."
               (car (cdr (cdr (cdr (process-command process)))))
               (substring signal 0 -1))))

(defun interactive-shell-command (command)
  (interactive "sCommand: ")
  (if (string-match  "[ \t]*&[ \t]*\\'" command)
      ;; asynchronous command
        (substring command 0 (match-beginning 0))) ;strip ampersand
      (set-buffer (get-buffer-create "*Shell Command Output*"))
      (let ((exit-code (call-process shell-file-name nil t t "-i" "-c" 
        (if (> (buffer-size) 0)
            (display-buffer (current-buffer))
          (progn (kill-buffer nil)
                 (if (eq exit-code 0)
                     (message "(Shell command succeeded with no output)")
                   (message "(Shell command failed with code %d and no output)"

(defun asynchronous-interactive-shell-command (command)
  (interactive "sCommand: ")
  (set-buffer (get-buffer-create "*Async Shell Command*"))
  (if (get-buffer-process (current-buffer))
      (progn (message "(An asynchronous process is already in progress)")
             (unless current-prefix-arg (display-buffer (current-buffer))))
    (progn (erase-buffer)
              (current-buffer) shell-file-name nil "-i" "-c" command))
             (setq mode-line-process '(":%s"))
             (unless current-prefix-arg (display-buffer (current-buffer))))))


reply via email to

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