Is there a way to get my emacs to recognize my bash aliases and custom functions when I run a shell command?

bash, emacs, environment-variables, shell

Solution

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

Problem

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?

Original source

Related problems