[Top][All Lists]

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

Re: Shell aliases as shell-commands

From: Sebastian Tennant
Subject: Re: Shell aliases as shell-commands
Date: Tue, 20 Jan 2009 15:40:39 +0000
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/22.2 (gnu/linux)

Quoth Peter Dyballa <address@hidden>:
> So make the shell used an interactive login shell! The variable
> shell-command-switch seems to be a good option to achieve this, just
> look into simple.el.

The key word in that sentence is _interactive_.  I was labouring under
the mistaken assumption that requesting a login shell was the way to
source my ~/.bashrc (via my ~/.profile), but it turns out the '-i'
switch is what's required.

 ---------------- ~/.bashrc ----------------
 alias ll="ls -al"
 ---------------- ~/.bashrc ----------------

 $ bash -l -c ll
 bash: ll: command not found

 $ bash -i -c ll
 [...] # success!

shell-command as it stands will not suffice because shell-command-switch
can only hold a single switch (and here I need two; -i and -c) but I
never expected to be able to use shell-command directly anyway.

Here's my function at last (which I've chosen to call
interactive-shell-command because you're not restricted to using

 (defun interactive-shell-command (command)
   (interactive "sCommand: ")
   (set-buffer (get-buffer-create "*Shell Command Output*"))
   (let ((exit-code (call-process "/bin/bash" nil t t "-i" "-c" command)))
     (if (> (buffer-size) 0)
         (display-buffer (current-buffer))
       (when (eq exit-code 0)
         (kill-buffer nil)
         (message "(Shell command succeeded with no output)")))))

Thanks to all for their suggestions.


reply via email to

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