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

前端 未结 5 1334
南笙
南笙 2020-12-02 20:30

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-!

5条回答
  •  情话喂你
    2020-12-02 21:11

    We need to enable alias expansion in non-interactive shells, preferably only when they are called from emacs (to avoid causing subtle differences when we run other shells). What worked for me was to create two files: ~/.alias has all my aliases, e.g.

    alias python python27
    

    and ~/.aliasExpand has

    source ~/.alias
    shopt -s expand_aliases
    

    I also, of course, replaced all my aliases in .bashrc with

    source ~/.alias
    

    Finally, I added this to my .emacs:

    (setenv "BASH_ENV" "~/.aliasExpand")
    

    I tried Keith Flower's solution (of making shells interactive), and I got

    bash: cannot set terminal process group (-1): Inappropriate ioctl for device bash: no job control in this shell

    Note that I got this through Glenn Jackman's and Nicholas Dudebout's hints.

    If you are willing to risk having all your shells have alias expansion and you don't mind running all your .bashrc for every emacs shell, you can simplify this to adding

    shopt -s expand_aliases
    

    to your .bashrc and

    (setenv "BASH_ENV" "~/.bashrc")
    

    to your .emacs

提交回复
热议问题