有没有办法让我的emacs在运行shell命令时识别我的bash别名和自定义函数?

时间:2022-06-13 10:56:49

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-x !) 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?

在我的shell环境中,我有别名和自定义函数。当我在emacs的实例(我总是使用emacs -nw)并执行shell命令(M-x!)时,我无法使用它们。这是有道理的,因为我想它启动它自己的子shell来做这些..但有没有办法(也许在我的.emacs中)让它工作?也许即使它在执行任何shell命令之前默认采购环境?

3 个解决方案

#1


27  

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):

我认为M-x shell-command和M-x编译都是通过call-process在劣质shell中执行命令。在.emacs中尝试以下内容(或仅评估):

(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

我注意到在评估了上述内容之后,选择.bashrc别名供M-x shell-command和M-x编译使用,即

M-x compile RET your_alias RET

M-x编译RET your_alias RET

should then work.

应该工作。

My environment: Emacs 24.1 (pretest rc1), OSX 10.7.3

我的环境:Emacs 24.1(预测试rc1),OSX 10.7.3

Source

资源

#2


0  

Have a read through http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

阅读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"

对于非交互式shell,唯一获取的文件是BASH_ENV环境变量的值。如果emacs将使用bash作为shell命令,你调用像BASH_ENV =〜/ .bashrc emacs这样的emacs - 一些程序专门使用“/ bin / sh”

#3


-1  

Put the aliases and functions in .bashrc, not .bash_profile. The latter is only executed in login shells, the former is in all shells.

将别名和函数放在.bashrc中,而不是.bash_profile。后者仅在登录shell中执行,前者在所有shell中执行。

#1


27  

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):

我认为M-x shell-command和M-x编译都是通过call-process在劣质shell中执行命令。在.emacs中尝试以下内容(或仅评估):

(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

我注意到在评估了上述内容之后,选择.bashrc别名供M-x shell-command和M-x编译使用,即

M-x compile RET your_alias RET

M-x编译RET your_alias RET

should then work.

应该工作。

My environment: Emacs 24.1 (pretest rc1), OSX 10.7.3

我的环境:Emacs 24.1(预测试rc1),OSX 10.7.3

Source

资源

#2


0  

Have a read through http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

阅读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"

对于非交互式shell,唯一获取的文件是BASH_ENV环境变量的值。如果emacs将使用bash作为shell命令,你调用像BASH_ENV =〜/ .bashrc emacs这样的emacs - 一些程序专门使用“/ bin / sh”

#3


-1  

Put the aliases and functions in .bashrc, not .bash_profile. The latter is only executed in login shells, the former is in all shells.

将别名和函数放在.bashrc中,而不是.bash_profile。后者仅在登录shell中执行,前者在所有shell中执行。