当我运行 shell 命令时,有没有办法让我的 emacs 识别我的 bash 别名和自定义函数? [英] Is there a way to get my emacs to recognize my bash aliases and custom functions when I run a shell command?
问题描述
在我的 shell 环境中,我有别名和自定义函数.当我在 emacs 的一个实例中(我总是使用 emacs -nw
)并且我执行一个 shell 命令(M-!
)我不能使用它们.这是有道理的,因为我想它会启动它自己的子外壳来执行这些...但是有没有办法(可能在我的 .emacs
中)让它工作?也许即使它涉及在执行任何给定的 shell 命令之前默认情况下采购环境?
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?
推荐答案
以下是我对我认为是相关问题的评论:
Below are my comments about what I think was a related question:
我认为 Mx shell-command 和 Mx compile 通过调用在低级 shell 中执行命令-过程.在您的 .emacs 中尝试以下操作(或只是评估):
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")
我注意到在评估上述内容后,M-x shell-command 和 M-x 编译都选择了 .bashrc 别名,即
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 编译 RET your_alias RET
应该可以工作.
我的环境:Emacs 24.1(预测试 rc1),OSX 10.7.3
My environment: Emacs 24.1 (pretest rc1), OSX 10.7.3
这篇关于当我运行 shell 命令时,有没有办法让我的 emacs 识别我的 bash 别名和自定义函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!