My goal is to have a set of dot files shared between the many shell accounts I have so that I can have a similar environment in each one. Because of that, I don't want machine/environment specific information in my .git files or my .bash files.
On my MacOSX machine, the default emacs version is 22. I have installed a newer version of emacs (24) in /usr/local/bin
. In my .bashrc file I set my default editor to emacs: export EDITOR=emacs
. Before this, I also set up my path so that /usr/local/bin
comes before /usr/bin
so that the newer version of emacs gets selected.
When I use git to create commit messages, it always picks the one in /usr/bin
instead of the one in /usr/local/bin
. Git is ignoring my $PATH
settings. I used to hardcode the location of the version of emacs I wanted in my .gitconfigure file, but that won't work when I use that same .gitconfigure file on my Ubuntu server. (If it's unclear, what I'm saying is that modifying my .gitconfigure editor option to point to a hardcoded won't work for me).
Why doesn't git respect my $PATH
settings?
How do I configure git to use the correct emacs?
Edit: Adding more context
There is a suggestion to put environment variables in .profile/.bash_profile
. Here's some relevant code from my .bashrc
and my .bash_profile
.bashrc
Note: I wrote a bash function called vercomp
which compares version numbers.
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
.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
I expect to have an answer that explains WHY MacOSX doesn't pick up my bashrc/profile environment changes and a solution to HOW I can get MacOSX to pick up those changes.
This is not specific to OS X - here is an example:
$ uname -a
Linux hostname 3.13.7-gentoo #1 SMP PREEMPT Mon Mar 24 18:40:46 CET 2014 i686 Intel(R) Atom(TM) CPU 330 @ 1.60GHz GenuineIntel GNU/Linux
$ cat .bashrc
export EDITOR="emacs"
$ echo $EDITOR
/usr/bin/vim
$ mv .bashrc .bash_profile
$ logout
Connection to hostname closed.
$ ssh hostname
$ echo $EDITOR
emacs
For what I know and used to "live" is that environment variables are expected to reside inside /etc/profile
(system wide) and can be extended and overwritten on a user level basis inside ~/.profile
respectively ~/.bash_profile
.
From man bash
:
When bash is invoked as an interactive login shell, or as a non-interac- tive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.
On the other hand. .bashrc
is the place to go where one places custom functions, aliases, prompt configuration, etc.
So a simple solution to your specific question - aside from using another git version in your special situation - would be to simply move your environmant variables from your .bashrc
into a .bash_profile
.
The Linux From Scratch project provides some pretty good examples about how to organize the bash shell startup files. Specific problems on OS X are tackled inside "Setting environment variables in OS X?".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With