* Shell aliases as shell-commands
@ 2009-01-19 21:11 Sebastian Tennant
2009-01-19 22:02 ` Peter Dyballa
0 siblings, 1 reply; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-19 21:11 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
I thought it would be trivial to implement a 'M-x alias' function that
would make aliases defined in one's ~/.bashrc available to 'M-x
shell-command' calls, but it's proving to be lot trickier than I
thought.
Does anyone know of an existing extension that provides this kind of
functionality?
Any tips/pointers/suggestions much appreciated.
Regards,
Sebastian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-19 21:11 Shell aliases as shell-commands Sebastian Tennant
@ 2009-01-19 22:02 ` Peter Dyballa
2009-01-20 9:09 ` Sebastian Tennant
0 siblings, 1 reply; 30+ messages in thread
From: Peter Dyballa @ 2009-01-19 22:02 UTC (permalink / raw)
To: Sebastian Tennant; +Cc: help-gnu-emacs
Am 19.01.2009 um 22:11 schrieb Sebastian Tennant:
> Does anyone know of an existing extension that provides this kind of
> functionality?
Have you read of ~/.emacs_bash? This one is executed when *shell*
buffer is created.
--
Greetings
Pete
Don't force it; get a larger hammer.
– Anthony's Law of Force
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
[not found] <mailman.5279.1232399379.26697.help-gnu-emacs@gnu.org>
@ 2009-01-19 22:53 ` Chetan
2009-01-20 9:07 ` Sebastian Tennant
0 siblings, 1 reply; 30+ messages in thread
From: Chetan @ 2009-01-19 22:53 UTC (permalink / raw)
To: help-gnu-emacs
Sebastian Tennant <sebyte@smolny.plus.com> writes:
> Hi all,
>
> I thought it would be trivial to implement a 'M-x alias' function that
> would make aliases defined in one's ~/.bashrc available to 'M-x
> shell-command' calls, but it's proving to be lot trickier than I
> thought.
>
> Does anyone know of an existing extension that provides this kind of
> functionality?
>
> Any tips/pointers/suggestions much appreciated.
>
> Regards,
>
> Sebastian
I have a .bash_aliases that I load from .bashrc, so have also used
. ~/.bash_aliases ; myalias
Chetan
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-19 22:53 ` Chetan
@ 2009-01-20 9:07 ` Sebastian Tennant
0 siblings, 0 replies; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-20 9:07 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Chetan <Chetan.xspam@xspam.sbcglobal.net>:
>> I thought it would be trivial to implement a 'M-x alias' function
>> that would make aliases defined in my ~/.bashrc available to
>> 'M-x >> shell-command' calls
> I have a .bash_aliases that I load from .bashrc, so have also used
> . ~/.bash_aliases ; myalias
Really? Doesn't work for me.
-- *scratch* buffer --
(shell-command ". ~/.bashrc; ll")
-| /bin/bash: ll: command not found
=> 127
-- end of buffer --
yet the alias 'll' is defined in my ~/.bashrc, like so:
alias ll="ls -l"
I also get the same result interactively.
M-x shell-command RET . ~/.bashrc; ll RET
Could you provide more detail as to how you access your aliases?
Sebastian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-19 22:02 ` Peter Dyballa
@ 2009-01-20 9:09 ` Sebastian Tennant
2009-01-20 9:38 ` Peter Dyballa
0 siblings, 1 reply; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-20 9:09 UTC (permalink / raw)
To: help-gnu-emacs
Hi Peter,
Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
> Am 19.01.2009 um 22:11 schrieb Sebastian Tennant:
>
>> Does anyone know of an existing extension that provides this kind of
>> functionality?
>
> Have you read of ~/.emacs_bash? This one is executed when *shell*
> buffer is created.
'M-x shell' is no problem.
It's 'M-x shell-command' I'm thinking about.
Sebastian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-20 9:09 ` Sebastian Tennant
@ 2009-01-20 9:38 ` Peter Dyballa
2009-01-20 10:18 ` Sebastian Tennant
[not found] ` <mailman.5330.1232446602.26697.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 30+ messages in thread
From: Peter Dyballa @ 2009-01-20 9:38 UTC (permalink / raw)
To: Sebastian Tennant; +Cc: help-gnu-emacs
Am 20.01.2009 um 10:09 schrieb Sebastian Tennant:
> It's 'M-x shell-command' I'm thinking about.
Forget it! Shell-command is not meant for interactive use as in a
shell with aliases and such comfort.
--
Greetings
Pete
A child of five could understand this! Fetch me a child of five.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-20 9:38 ` Peter Dyballa
@ 2009-01-20 10:18 ` Sebastian Tennant
2009-01-20 11:43 ` Peter Dyballa
[not found] ` <mailman.5330.1232446602.26697.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-20 10:18 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
> Am 20.01.2009 um 10:09 schrieb Sebastian Tennant:
>
>> It's 'M-x shell-command' I'm thinking about.
>
> Forget it! Shell-command is not meant for interactive use as in a
> shell with aliases and such comfort.
But my aliases are so handy!!! I want them (without having to run an
interactive shell), and Emacs can give them to me, I know it can :)
Another approach I'm considering is parsing my bashrc so that
'M-x alias NAME'
will simply issue the command associated with NAME as a shell-command.
Haven't had much experience writing parsers though? Any tips?
Seb
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
[not found] ` <mailman.5330.1232446602.26697.help-gnu-emacs@gnu.org>
@ 2009-01-20 11:02 ` Teemu Likonen
2009-01-20 11:10 ` Sebastian Tennant
2009-01-21 5:46 ` Barry Margolin
` (2 subsequent siblings)
3 siblings, 1 reply; 30+ messages in thread
From: Teemu Likonen @ 2009-01-20 11:02 UTC (permalink / raw)
To: Sebastian Tennant; +Cc: help-gnu-emacs
Sebastian Tennant (2009-01-20 10:18 +0000) wrote:
> Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
>> Am 20.01.2009 um 10:09 schrieb Sebastian Tennant:
>>
>>> It's 'M-x shell-command' I'm thinking about.
>>
>> Forget it! Shell-command is not meant for interactive use as in a
>> shell with aliases and such comfort.
>
> But my aliases are so handy!!! I want them (without having to run an
> interactive shell), and Emacs can give them to me, I know it can :)
Aliases work in interactive shell. If you want to use some "aliases"
outside an interactive shell turn them into shell scripts.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-20 11:02 ` Teemu Likonen
@ 2009-01-20 11:10 ` Sebastian Tennant
0 siblings, 0 replies; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-20 11:10 UTC (permalink / raw)
To: Teemu Likonen; +Cc: help-gnu-emacs
Quoth Teemu Likonen <tlikonen@iki.fi>:
> Sebastian Tennant (2009-01-20 10:18 +0000) wrote:
>
>> Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
>>> Am 20.01.2009 um 10:09 schrieb Sebastian Tennant:
>>>
>>>> It's 'M-x shell-command' I'm thinking about.
>>>
>>> Forget it! Shell-command is not meant for interactive use as in a
>>> shell with aliases and such comfort.
>>
>> But my aliases are so handy!!! I want them (without having to run an
>> interactive shell), and Emacs can give them to me, I know it can :)
>
> Aliases work in interactive shell. If you want to use some "aliases"
> outside an interactive shell turn them into shell scripts.
Which is a lot of work (and not much fun :)
Hence my plan to parse my ~/.bashrc (or alias file) and define a command
'M-x alias' which maps names of aliases to their respective definitions.
Anyone have any tips on how best to write the parsing routines?
Seb
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-20 10:18 ` Sebastian Tennant
@ 2009-01-20 11:43 ` Peter Dyballa
2009-01-20 15:40 ` Sebastian Tennant
0 siblings, 1 reply; 30+ messages in thread
From: Peter Dyballa @ 2009-01-20 11:43 UTC (permalink / raw)
To: Sebastian Tennant; +Cc: help-gnu-emacs
Am 20.01.2009 um 11:18 schrieb Sebastian Tennant:
> But my aliases are so handy!!!
OK! 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 variable shell-command-history could also be
set to true to refer to earlier commands ...
--
Greetings
Pete
UNIX is user friendly, it's just picky about who its friends are.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-20 11:43 ` Peter Dyballa
@ 2009-01-20 15:40 ` Sebastian Tennant
2009-01-20 16:43 ` Peter Dyballa
2009-01-20 17:09 ` Thierry Volpiatto
0 siblings, 2 replies; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-20 15:40 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
> 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
aliases:
(defun interactive-shell-command (command)
(interactive "sCommand: ")
(set-buffer (get-buffer-create "*Shell Command Output*"))
(erase-buffer)
(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.
Sebastian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-20 15:40 ` Sebastian Tennant
@ 2009-01-20 16:43 ` Peter Dyballa
2009-01-20 17:09 ` Thierry Volpiatto
1 sibling, 0 replies; 30+ messages in thread
From: Peter Dyballa @ 2009-01-20 16:43 UTC (permalink / raw)
To: Sebastian Tennant; +Cc: help-gnu-emacs
Am 20.01.2009 um 16:40 schrieb Sebastian Tennant:
> $ bash -l -c ll
> bash: ll: command not found
>
> $ bash -i -c ll
> [...] # success!
And 'bash -li -c ll'? M-x unix-manual RET bash RET explains your
failure. And success.
--
Greetings
Pete
One cannot live by television, video games, top ten CDs, and dumb
movies alone.
– Amiri Baraka, 1999
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-20 15:40 ` Sebastian Tennant
2009-01-20 16:43 ` Peter Dyballa
@ 2009-01-20 17:09 ` Thierry Volpiatto
2009-01-20 18:03 ` Sebastian Tennant
1 sibling, 1 reply; 30+ messages in thread
From: Thierry Volpiatto @ 2009-01-20 17:09 UTC (permalink / raw)
To: help-gnu-emacs
Sebastian Tennant <sebyte@smolny.plus.com> writes:
> Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
>> 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
> aliases:
>
> (defun interactive-shell-command (command)
> (interactive "sCommand: ")
> (set-buffer (get-buffer-create "*Shell Command Output*"))
> (erase-buffer)
> (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)")))))
>
Have a look also at M-x eshell-command, you will have alias and
completion on filenames.
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-20 17:09 ` Thierry Volpiatto
@ 2009-01-20 18:03 ` Sebastian Tennant
0 siblings, 0 replies; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-20 18:03 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Thierry Volpiatto <thierry.volpiatto@gmail.com>:
> Have a look also at M-x eshell-command, you will have alias and
> completion on filenames.
Yes, eshell is great, and one day I do intend to start using it.
Sebastian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
[not found] ` <mailman.5330.1232446602.26697.help-gnu-emacs@gnu.org>
2009-01-20 11:02 ` Teemu Likonen
@ 2009-01-21 5:46 ` Barry Margolin
2009-01-21 10:51 ` Sebastian Tennant
2009-01-21 10:40 ` Michael Heerdegen
[not found] ` <mailman.5332.1232449359.26697.help-gnu-emacs@gnu.org>
3 siblings, 1 reply; 30+ messages in thread
From: Barry Margolin @ 2009-01-21 5:46 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.5330.1232446602.26697.help-gnu-emacs@gnu.org>,
Sebastian Tennant <sebyte@smolny.plus.com> wrote:
> Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
> > Am 20.01.2009 um 10:09 schrieb Sebastian Tennant:
> >
> >> It's 'M-x shell-command' I'm thinking about.
> >
> > Forget it! Shell-command is not meant for interactive use as in a
> > shell with aliases and such comfort.
>
> But my aliases are so handy!!! I want them (without having to run an
> interactive shell), and Emacs can give them to me, I know it can :)
Can you define them as functions instead of aliases?
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
[not found] ` <mailman.5330.1232446602.26697.help-gnu-emacs@gnu.org>
2009-01-20 11:02 ` Teemu Likonen
2009-01-21 5:46 ` Barry Margolin
@ 2009-01-21 10:40 ` Michael Heerdegen
2009-01-21 15:26 ` Sebastian Tennant
[not found] ` <mailman.5443.1232551479.26697.help-gnu-emacs@gnu.org>
[not found] ` <mailman.5332.1232449359.26697.help-gnu-emacs@gnu.org>
3 siblings, 2 replies; 30+ messages in thread
From: Michael Heerdegen @ 2009-01-21 10:40 UTC (permalink / raw)
To: help-gnu-emacs
It is possible to use your aliases with M-x shell-command, I do it all
the time. Do the following:
* in you bash config (.bashrc): shopt -s -q expand_aliases
This makes bash aliases work in non-interactive bashs.
* In your emacs config (.emacs): (setenv "BASH_ENV" "~/.bashrc")
This tells emacs that non-interactive bash subprocesses should
load .bashrc.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-21 5:46 ` Barry Margolin
@ 2009-01-21 10:51 ` Sebastian Tennant
0 siblings, 0 replies; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-21 10:51 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Barry Margolin <barmar@alum.mit.edu>:
> In article <mailman.5330.1232446602.26697.help-gnu-emacs@gnu.org>,
> Sebastian Tennant <sebyte@smolny.plus.com> wrote:
>
>> Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
>> > Am 20.01.2009 um 10:09 schrieb Sebastian Tennant:
>> >
>> >> It's 'M-x shell-command' I'm thinking about.
>> >
>> > Forget it! Shell-command is not meant for interactive use as in a
>> > shell with aliases and such comfort.
>>
>> But my aliases are so handy!!! I want them (without having to run an
>> interactive shell), and Emacs can give them to me, I know it can :)
>
> Can you define them as functions instead of aliases?
The issue was over instructing the shell to source my ~/.bashrc (which
contains both aliases and functions).
I mistakenly thought that the way to get a shell to read init files was
to specify a login shell (bash -l -c <command>), but that isn't the way
to do it, rather, you should force interactive behaviour with the '-i'
switch (bash -i -c <command>). Do this and all your aliases and
functions are to hand.
Here are the two functions I posted to emacs.sources that force
interactive shells and put all your aliases and function defs at your
fingertips.
http://article.gmane.org/gmane.emacs.sources/3147
The previous post (3146) contains a little bit of explanation but don't
use the code from 3146 or you'll break shell-command (slightly).
If you have lots of aliases and functions you'd like to access via
M-! <command>
you may like to rebind M-! to interactive-shell-command, like so:
(global-set-key "M-!" 'interactive-shell-command)
Sebastian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-21 10:40 ` Michael Heerdegen
@ 2009-01-21 15:26 ` Sebastian Tennant
2009-01-21 15:49 ` Peter Dyballa
[not found] ` <mailman.5445.1232552977.26697.help-gnu-emacs@gnu.org>
[not found] ` <mailman.5443.1232551479.26697.help-gnu-emacs@gnu.org>
1 sibling, 2 replies; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-21 15:26 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Michael Heerdegen <michael_heerdegen@web.de>:
> It is possible to use your aliases [and functions] with M-x
> shell-command, I do it all the time. Do the following:
>
> * in you bash config (.bashrc): shopt -s -q expand_aliases
> This makes bash aliases work in non-interactive bashs.
>
> * In your emacs config (.emacs): (setenv "BASH_ENV" "~/.bashrc")
> This tells emacs that non-interactive bash subprocesses should
> load .bashrc.
Damn that's a good tip. Guess I should tell the folks over at
emacs.sources... there was me thinking I'd written something useful!
Sebastian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-21 15:26 ` Sebastian Tennant
@ 2009-01-21 15:49 ` Peter Dyballa
2009-01-21 17:07 ` Sebastian Tennant
[not found] ` <mailman.5445.1232552977.26697.help-gnu-emacs@gnu.org>
1 sibling, 1 reply; 30+ messages in thread
From: Peter Dyballa @ 2009-01-21 15:49 UTC (permalink / raw)
To: Sebastian Tennant; +Cc: help-gnu-emacs
Am 21.01.2009 um 16:26 schrieb Sebastian Tennant:
>> * In your emacs config (.emacs): (setenv "BASH_ENV" "~/.bashrc")
>> This tells emacs that non-interactive bash subprocesses should
>> load .bashrc.
>
> Damn that's a good tip. Guess I should tell the folks over at
> emacs.sources...
Not that fast, Sebastian! The solution with BASH_ENV will introduce
problems with non-interactive bash shell scripts! The solution I
suggested is valid only inside GNU Emacs; this is the proper way.
--
Greetings
Pete
Clovis' Consideration of an Atmospheric Anomaly:
The perversity of nature is nowhere better demonstrated
than by the fact that, when exposed to the same atmosphere,
bread becomes hard while crackers become soft.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-21 15:49 ` Peter Dyballa
@ 2009-01-21 17:07 ` Sebastian Tennant
2009-01-21 18:26 ` Peter Dyballa
0 siblings, 1 reply; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-21 17:07 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
> Am 21.01.2009 um 16:26 schrieb Sebastian Tennant:
>
>>> * In your emacs config (.emacs): (setenv "BASH_ENV" "~/.bashrc")
>>> This tells emacs that non-interactive bash subprocesses should
>>> load .bashrc.
>>
>> Damn that's a good tip. Guess I should tell the folks over at
>> emacs.sources...
>
> Not that fast, Sebastian! The solution with BASH_ENV will introduce
> problems with non-interactive bash shell scripts!
I'm not sure what you mean by non-interactive [...] scripts?
`BASH_ENV'
If this variable is set when Bash is invoked to execute a shell
script, its value is expanded and used as the name of a startup
file to read before executing the script.
If people set this variable, they can't complain if it then causes them
problems. After all, it's simply doing what it's designed to do!
> The solution I suggested is valid only inside GNU Emacs; this is the
> proper way.
Forgive me, but I thought I'd explained why your solution wasn't exactly
a solution.
The variable shell-command-switch can only hold a single switch and we
need to call bash with two switches; -i _and_ -c if we want
shell-command to have access to aliases (and functions). This is why I
went ahead and wrote interactive-shell-command (essentially a simpler
version of shell-command that calls shell-file-name (bash) with both
switches.
Sebastian
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-21 17:07 ` Sebastian Tennant
@ 2009-01-21 18:26 ` Peter Dyballa
0 siblings, 0 replies; 30+ messages in thread
From: Peter Dyballa @ 2009-01-21 18:26 UTC (permalink / raw)
To: Sebastian Tennant; +Cc: help-gnu-emacs
Am 21.01.2009 um 18:07 schrieb Sebastian Tennant:
> I'm not sure what you mean by non-interactive [...] scripts?
Shell scripts, cron or at jobs, lp(r) handling ...
--
Greetings
Pete
They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety.
-Benjamin Franklin, Historical Review of Pennsylvania.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
[not found] ` <mailman.5445.1232552977.26697.help-gnu-emacs@gnu.org>
@ 2009-01-22 11:52 ` Michael Heerdegen
2009-01-22 13:51 ` Peter Dyballa
` (2 more replies)
0 siblings, 3 replies; 30+ messages in thread
From: Michael Heerdegen @ 2009-01-22 11:52 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
I agree that that my solution with BASH_ENV is not very clean. I would
suggest the following elisp code which works without setting env vars:
(defadvice shell-command (before my-shell-command activate)
(ad-set-arg
0
(concat "source ~/.bashrc; shopt -s -q expand_aliases;\n "
(ad-get-arg 0))))
(you could replace .bashrc by an individual file especially written
for that purpose).
What do you think about it?
Michael
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-22 11:52 ` Michael Heerdegen
@ 2009-01-22 13:51 ` Peter Dyballa
2009-01-22 20:26 ` Sebastian Tennant
2009-01-22 13:57 ` Thierry Volpiatto
[not found] ` <mailman.5510.1232633053.26697.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 30+ messages in thread
From: Peter Dyballa @ 2009-01-22 13:51 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
Am 22.01.2009 um 12:52 schrieb Michael Heerdegen:
> (you could replace .bashrc by an individual file especially written
> for that purpose).
>
> What do you think about it?
It could even be ~/.emacs_bash, I think. This would be perfect, since
*shell* buffer and shell commands would then see the same environment.
--
Mit friedvollen Grüßen
Pete
Debugging? Klingons do not debug. Our software does not coddle the weak.
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-22 11:52 ` Michael Heerdegen
2009-01-22 13:51 ` Peter Dyballa
@ 2009-01-22 13:57 ` Thierry Volpiatto
[not found] ` <mailman.5510.1232633053.26697.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 30+ messages in thread
From: Thierry Volpiatto @ 2009-01-22 13:57 UTC (permalink / raw)
To: help-gnu-emacs
Michael Heerdegen <michael_heerdegen@web.de> writes:
> Hello,
>
> I agree that that my solution with BASH_ENV is not very clean. I would
> suggest the following elisp code which works without setting env vars:
>
> (defadvice shell-command (before my-shell-command activate)
> (ad-set-arg
> 0
> (concat "source ~/.bashrc; shopt -s -q expand_aliases;\n "
> (ad-get-arg 0))))
>
> (you could replace .bashrc by an individual file especially written
> for that purpose).
>
> What do you think about it?
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
Now (i bind eshell-command to C-!)
C-! Mcle ==> mount my usbkey
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
[not found] ` <mailman.5510.1232633053.26697.help-gnu-emacs@gnu.org>
@ 2009-01-22 17:55 ` Michael Heerdegen
2009-01-22 20:35 ` Sebastian Tennant
0 siblings, 1 reply; 30+ messages in thread
From: Michael Heerdegen @ 2009-01-22 17:55 UTC (permalink / raw)
To: help-gnu-emacs
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'?
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-22 13:51 ` Peter Dyballa
@ 2009-01-22 20:26 ` Sebastian Tennant
0 siblings, 0 replies; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-22 20:26 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
> Am 22.01.2009 um 12:52 schrieb Michael Heerdegen:
>
>> (you could replace .bashrc by an individual file especially written
>> for that purpose).
>>
>> What do you think about it?
It works a treat, and although I wasn't as concerned as Peter was about
setting BASH_ENV, it _is_ good to know that scripts can be called from
Emacs' *shell* buffer without ~/.bashrc being sourced each time.
> It could even be ~/.emacs_bash, I think. This would be perfect, since
> *shell* buffer and shell commands would then see the same environment.
The default value of explicit-bash-args is ("-i" "--noediting") so
unless you've removed "-i" from the list the advice would need to cause
~/.emacs_bash _and_ ~/.bashrc to be sourced for buffer *shell* and
shell-command's execution environment to be the same.
Sebastian
--
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-01-22 17:55 ` Michael Heerdegen
@ 2009-01-22 20:35 ` Sebastian Tennant
0 siblings, 0 replies; 30+ messages in thread
From: Sebastian Tennant @ 2009-01-22 20:35 UTC (permalink / raw)
To: help-gnu-emacs
Quoth Michael Heerdegen <michael_heerdegen@web.de>:
> Is it possible to get this work with `eshell-command'?
A question I'm keen to see answered too, and I'm bound to have questions
of my own. May I suggest you start a new thread Thierry.
Sebastian
--
Emacs' AlsaPlayer - Music Without Jolts
Lightweight, full-featured and mindful of your idyllic happiness.
http://home.gna.org/eap
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
[not found] ` <mailman.5332.1232449359.26697.help-gnu-emacs@gnu.org>
@ 2009-02-17 15:08 ` David Combs
0 siblings, 0 replies; 30+ messages in thread
From: David Combs @ 2009-02-17 15:08 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.5332.1232449359.26697.help-gnu-emacs@gnu.org>,
Teemu Likonen <tlikonen@iki.fi> wrote:
>Sebastian Tennant (2009-01-20 10:18 +0000) wrote:
>
>> Quoth Peter Dyballa <Peter_Dyballa@Web.DE>:
>>> Am 20.01.2009 um 10:09 schrieb Sebastian Tennant:
>>>
>>>> It's 'M-x shell-command' I'm thinking about.
>>>
>>> Forget it! Shell-command is not meant for interactive use as in a
>>> shell with aliases and such comfort.
>>
>> But my aliases are so handy!!! I want them (without having to run an
>> interactive shell), and Emacs can give them to me, I know it can :)
>
>Aliases work in interactive shell. If you want to use some "aliases"
>outside an interactive shell turn them into shell scripts.
>
>
Anyone know of a program or script that can automate that?
David
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
[not found] ` <mailman.5443.1232551479.26697.help-gnu-emacs@gnu.org>
@ 2009-02-17 15:14 ` David Combs
2009-02-17 23:18 ` Peter Dyballa
0 siblings, 1 reply; 30+ messages in thread
From: David Combs @ 2009-02-17 15:14 UTC (permalink / raw)
To: help-gnu-emacs
In article <mailman.5443.1232551479.26697.help-gnu-emacs@gnu.org>,
Sebastian Tennant <sebyte@smolny.plus.com> wrote:
>Quoth Michael Heerdegen <michael_heerdegen@web.de>:
>> It is possible to use your aliases [and functions] with M-x
>> shell-command, I do it all the time. Do the following:
>>
>> * in you bash config (.bashrc): shopt -s -q expand_aliases
>> This makes bash aliases work in non-interactive bashs.
>>
>> * In your emacs config (.emacs): (setenv "BASH_ENV" "~/.bashrc")
>> This tells emacs that non-interactive bash subprocesses should
>> load .bashrc.
>
>Damn that's a good tip. Guess I should tell the folks over at
>emacs.sources... there was me thinking I'd written something useful!
>
>Sebastian
And suppose you use, say, tcsh.
How to get (at least) dired "!" to use tcsh, read its aliasaes, etc?
Thanks,
David
^ permalink raw reply [flat|nested] 30+ messages in thread
* Re: Shell aliases as shell-commands
2009-02-17 15:14 ` David Combs
@ 2009-02-17 23:18 ` Peter Dyballa
0 siblings, 0 replies; 30+ messages in thread
From: Peter Dyballa @ 2009-02-17 23:18 UTC (permalink / raw)
To: David Combs; +Cc: help-gnu-emacs
Am 17.02.2009 um 16:14 schrieb David Combs:
> How to get (at least) dired "!" to use tcsh, read its aliasaes, etc?
Put them into ~/.cshrc or ~/.tcshrc! You can start for a test to
insert an
echo "Hi Jack! It's me, your ~/.(t)cshrc!"
You can restrict things by checking whether $_ is the name by which
you invoked GNU Emacs.
--
Greetings
Pete
Know thyself. Need help, call GOOGLE.
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2009-02-17 23:18 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-19 21:11 Shell aliases as shell-commands Sebastian Tennant
2009-01-19 22:02 ` Peter Dyballa
2009-01-20 9:09 ` Sebastian Tennant
2009-01-20 9:38 ` Peter Dyballa
2009-01-20 10:18 ` Sebastian Tennant
2009-01-20 11:43 ` Peter Dyballa
2009-01-20 15:40 ` Sebastian Tennant
2009-01-20 16:43 ` Peter Dyballa
2009-01-20 17:09 ` Thierry Volpiatto
2009-01-20 18:03 ` Sebastian Tennant
[not found] ` <mailman.5330.1232446602.26697.help-gnu-emacs@gnu.org>
2009-01-20 11:02 ` Teemu Likonen
2009-01-20 11:10 ` Sebastian Tennant
2009-01-21 5:46 ` Barry Margolin
2009-01-21 10:51 ` Sebastian Tennant
2009-01-21 10:40 ` Michael Heerdegen
2009-01-21 15:26 ` Sebastian Tennant
2009-01-21 15:49 ` Peter Dyballa
2009-01-21 17:07 ` Sebastian Tennant
2009-01-21 18:26 ` Peter Dyballa
[not found] ` <mailman.5445.1232552977.26697.help-gnu-emacs@gnu.org>
2009-01-22 11:52 ` Michael Heerdegen
2009-01-22 13:51 ` Peter Dyballa
2009-01-22 20:26 ` Sebastian Tennant
2009-01-22 13:57 ` Thierry Volpiatto
[not found] ` <mailman.5510.1232633053.26697.help-gnu-emacs@gnu.org>
2009-01-22 17:55 ` Michael Heerdegen
2009-01-22 20:35 ` Sebastian Tennant
[not found] ` <mailman.5443.1232551479.26697.help-gnu-emacs@gnu.org>
2009-02-17 15:14 ` David Combs
2009-02-17 23:18 ` Peter Dyballa
[not found] ` <mailman.5332.1232449359.26697.help-gnu-emacs@gnu.org>
2009-02-17 15:08 ` David Combs
[not found] <mailman.5279.1232399379.26697.help-gnu-emacs@gnu.org>
2009-01-19 22:53 ` Chetan
2009-01-20 9:07 ` Sebastian Tennant
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).