In my shell environment I have aliases and custom functions. When I am in an instance of emacs (I always use emacs -nw
) and I execute a shell command (M-!
) I cannot use them. This makes sense since I imagine it launches it's own subshell to do these... but is there a way (maybe in my .emacs
) to get this to work? Perhaps even if it involved sourcing an environment by default before executing any shell command given?
You can execute an external shell command from within Emacs using ` M-! ' ( 'shell-command' ). The output from the shell command is displayed in the minibuffer or in a separate buffer, depending on the output size.
How to list existing Bash Alias? You can use the alias -p command to list all the alias currently defined. that contains the list of aliases as created by the Bash alias builtin. $BASH_ALIASES will lose its special properties when being unset.
Your alias is well defined, but you have to store it in ~/. bashrc , not in a shell script. Add it to that file and then source it with . . bashrc - it will load the file so that alias will be possible to use.
Below are my comments about what I think was a related question:
I think both M-x shell-command and M-x compile execute commands in an inferior shell via call-process. Try the following in your .emacs (or just evaluate):
(setq shell-file-name "bash") (setq shell-command-switch "-ic")
I notice that after evaluation of the above, .bashrc aliases are picked up for use by both M-x shell-command and M-x compile, i.e
M-x compile RET your_alias RET
should then work.
My environment: Emacs 24.1 (pretest rc1), OSX 10.7.3
Source
Have a read through http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files
For non-interactive shells, the only file that is sourced is the value of the BASH_ENV environment variable. You invoke emacs like BASH_ENV=~/.bashrc emacs
if emacs will use bash for shell commands -- some programs specifically use "/bin/sh"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With