如何配置git继承我特定的$ PATH环境变量?

Ave*_*ery 7 git macos emacs bash

我的目标是在我拥有的许多shell帐户之间共享一组点文件,以便我可以在每个帐户中拥有类似的环境.因此,我不希望我的.git文件或.bash文件中的机器/环境特定信息.

在我的MacOSX机器上,默认的emacs版本是22.我已经安装了较新版本的emacs(24)/usr/local/bin.在我的.bashrc文件中,我将默认编辑器设置为emacs : export EDITOR=emacs. 在此之前,我还设置了我/usr/local/bin之前的路径,以便/usr/bin选择较新版本的emacs.

当我使用git创建提交消息时,它总是选择一个/usr/bin而不是一个/usr/local/bin.Git忽略了我的$PATH设置.我曾经在我的.gitconfigure文件中硬编码我想要的emacs版本的位置,但是当我在我的Ubuntu服务器上使用相同的.gitconfigure文件时,这不起作用.(如果不清楚,我所说的是修改我的.gitconfigure编辑器选项以指向硬编码对我来说不起作用).

为什么git不尊重我的$PATH设置?

如何配置git以使用正确的emacs?


编辑:添加更多上下文

有一个建议将环境变量放入.profile/.bash_profile.这是我.bashrc和我的一些相关代码.bash_profile

.bashrc

注意:我写了一个名为bash的函数vercomp来比较版本号.

OS=''                                                                                                
case $OSTYPE in                                                                                      
  darwin*)  OS='Mac' ;;                                                                              
  linux*)   OS='Linux'  ;;                                                                           
  *)        OS='UNKNOWN' ;;                                                                          
esac                                                                                                 

export EDITOR=emacs 

if [[ $OS = 'Mac' ]]; then                                                                           
    ### EMACS VERSION CHECK                                                                          
    # make sure that we're working with emacs >= 24                                                  
    wanted_ver=24                                                                                    
    curr_ver=`emacs --version | grep -oE '[[:digit:]]+\.[.[:digit:]]*'`                              
    vercomp $curr_ver $wanted_ver                                                                    

    # If vercomp returns 2, then our current emacs version isn't good enough.                        
    if [[ $? == 2 ]]; then                                                                           
        if [[ -e '/usr/local/bin/emacs' ]]; then                                                     
            emacs_path='/usr/local/bin/emacs -nw'                                                    
        elif  [[ -e '/Applications/Emacs.app/Contents/MacOS/Emacs' ]]; then                          
            emacs_path='/Applications/Emacs.app/Contents/MacOS/Emacs -nw'                            
        else                                                                                         
            echo -n "EMACS VERSION OUT OF DATE: $curr_emacs_version. "                               
            echo 'Install a newer version.'                                                          
            emacs_path=''                                                                            
        fi                                                                                           
        export EDITOR="$emacs_path"                                                                  
        alias emacs="$emacs_path"                                                                    
    fi                                                                                               
fi 
Run Code Online (Sandbox Code Playgroud)

.bash_profile

source ~/.bashrc                                                                                     
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell         
session *as a function*                                                                              
LESS=-FRX;export LESS  
Run Code Online (Sandbox Code Playgroud)

abo*_*abo -1

尝试这个:

export VISUAL=emacs
Run Code Online (Sandbox Code Playgroud)

我刚刚export VISUAL=gedit在 Ubuntu 上尝试使用 bash,现在 git 在从该终端调用时使用 gedit。