unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Emacs on Mac 10.7 (Lion): how to get PATH as in terminal?
@ 2011-10-23 20:58 Marius Hofert
  2011-10-23 21:17 ` Perry Smith
  0 siblings, 1 reply; 5+ messages in thread
From: Marius Hofert @ 2011-10-23 20:58 UTC (permalink / raw)
  To: Emacs help

Hi,

I know this is an old problem, but I still couldn't figure it out with the tricks I found.
I work with the emacs 23.3 on Mac OS X 10.7.2 (Lion), installed from http://emacsformacosx.com/
When I open a shell with M-x shell and type echo $PATH, I get:
/usr/bin:/bin:/usr/sbin:/sbin
When I do the same in Mac's Terminal, I get:
/Applications/Emacs.app/Contents/MacOS/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:/opt/local/bin:/opt/local/sbin

Question: How do I get the same PATH in emacs than in the terminal?

Trials:

1) fixpath.el:
(add-to-list 'load-path "~/.emacs.d/fixpath"); see https://svn.fsg.ulaval.ca/svn-pub/vgoulet/emacs-modified/macos/tags/Emacs-23.3-modified-3/fixpath.el
(require 'fixpath)

2) emacs wiki (http://www.emacswiki.org/emacs/EmacsApp#toc2)
;; add "defaults..." to /etc/profile:
if [ -x /usr/libexec/path_helper ]; then
         eval `/usr/libexec/path_helper -s`
         defaults write $HOME/.MacOSX/environment PATH "$PATH"
fi
;; add the following to .emacs:
(add-to-list 'exec-path "/usr/bin")

3) another solution posted on the emacs wiki page:
;; read in PATH from .bashrc (and add at least those directories)
;; see http://www.emacswiki.org/emacs/EmacsApp#toc5
(if (not (getenv "TERM_PROGRAM"))
     (setenv "PATH"
             (shell-command-to-string "source $HOME/.bashrc && printf $PATH")))

Cheers,

Marius


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs on Mac 10.7 (Lion): how to get PATH as in terminal?
  2011-10-23 20:58 Emacs on Mac 10.7 (Lion): how to get PATH as in terminal? Marius Hofert
@ 2011-10-23 21:17 ` Perry Smith
  2011-10-23 21:57   ` Marius Hofert
  0 siblings, 1 reply; 5+ messages in thread
From: Perry Smith @ 2011-10-23 21:17 UTC (permalink / raw)
  To: Marius Hofert; +Cc: Emacs help


On Oct 23, 2011, at 3:58 PM, Marius Hofert wrote:

> Hi,
> 
> I know this is an old problem, but I still couldn't figure it out with the tricks I found.
> I work with the emacs 23.3 on Mac OS X 10.7.2 (Lion), installed from http://emacsformacosx.com/
> When I open a shell with M-x shell and type echo $PATH, I get:
> /usr/bin:/bin:/usr/sbin:/sbin
> When I do the same in Mac's Terminal, I get:
> /Applications/Emacs.app/Contents/MacOS/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:/opt/local/bin:/opt/local/sbin
> 
> Question: How do I get the same PATH in emacs than in the terminal?
> 
> Trials:
> 
> 1) fixpath.el:
> (add-to-list 'load-path "~/.emacs.d/fixpath"); see https://svn.fsg.ulaval.ca/svn-pub/vgoulet/emacs-modified/macos/tags/Emacs-23.3-modified-3/fixpath.el
> (require 'fixpath)
> 
> 2) emacs wiki (http://www.emacswiki.org/emacs/EmacsApp#toc2)
> ;; add "defaults..." to /etc/profile:
> if [ -x /usr/libexec/path_helper ]; then
>         eval `/usr/libexec/path_helper -s`
>         defaults write $HOME/.MacOSX/environment PATH "$PATH"
> fi
> ;; add the following to .emacs:
> (add-to-list 'exec-path "/usr/bin")
> 
> 3) another solution posted on the emacs wiki page:
> ;; read in PATH from .bashrc (and add at least those directories)
> ;; see http://www.emacswiki.org/emacs/EmacsApp#toc5
> (if (not (getenv "TERM_PROGRAM"))
>     (setenv "PATH"
>             (shell-command-to-string "source $HOME/.bashrc && printf $PATH")))

I did not download the emacs that you did and dig around so I am sorta half guessing.

Recently while dinking with rvm, I discovered that bash is not being started with --login.

Since the M-x shell has fewer parts in its path, I would suspect that the additional
paths are being specified in /etc/profile.  Without bash thinking it is a login shell,
/etc/profile is not being sourced.  One way is to start it with a - as the first character in
arg0.  The other way is to start it with --login.

To explore if this is right: find where the parts for longer path are being set.  One
choice is /etc/profile, another is your ~/.profile.  If these parts are in the profile but
not in your .bashrc, then we are likely on the right track.

If that is the case, then review explicit-bash-args.  You can customize them and add --login
see if that works.  I'm a bit surprised this isn't done in the stock version of the code.

If you have a .profile,.bash_profile,
or .bashrc, you can echo the path at the very top of each and open a new term window.  This will
tell you where / how PATH is being set as it goes through your sequence of login scripts.

Hope this helps,
pedz




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs on Mac 10.7 (Lion): how to get PATH as in terminal?
  2011-10-23 21:17 ` Perry Smith
@ 2011-10-23 21:57   ` Marius Hofert
  2011-10-23 23:15     ` Perry Smith
  0 siblings, 1 reply; 5+ messages in thread
From: Marius Hofert @ 2011-10-23 21:57 UTC (permalink / raw)
  To: Perry Smith; +Cc: Emacs help


On 2011-10-23, at 23:17 , Perry Smith wrote:

> 
> On Oct 23, 2011, at 3:58 PM, Marius Hofert wrote:
> 
>> Hi,
>> 
>> I know this is an old problem, but I still couldn't figure it out with the tricks I found.
>> I work with the emacs 23.3 on Mac OS X 10.7.2 (Lion), installed from http://emacsformacosx.com/
>> When I open a shell with M-x shell and type echo $PATH, I get:
>> /usr/bin:/bin:/usr/sbin:/sbin
>> When I do the same in Mac's Terminal, I get:
>> /Applications/Emacs.app/Contents/MacOS/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:/opt/local/bin:/opt/local/sbin
>> 
>> Question: How do I get the same PATH in emacs than in the terminal?
>> 
>> Trials:
>> 
>> 1) fixpath.el:
>> (add-to-list 'load-path "~/.emacs.d/fixpath"); see https://svn.fsg.ulaval.ca/svn-pub/vgoulet/emacs-modified/macos/tags/Emacs-23.3-modified-3/fixpath.el
>> (require 'fixpath)
>> 
>> 2) emacs wiki (http://www.emacswiki.org/emacs/EmacsApp#toc2)
>> ;; add "defaults..." to /etc/profile:
>> if [ -x /usr/libexec/path_helper ]; then
>>        eval `/usr/libexec/path_helper -s`
>>        defaults write $HOME/.MacOSX/environment PATH "$PATH"
>> fi
>> ;; add the following to .emacs:
>> (add-to-list 'exec-path "/usr/bin")
>> 
>> 3) another solution posted on the emacs wiki page:
>> ;; read in PATH from .bashrc (and add at least those directories)
>> ;; see http://www.emacswiki.org/emacs/EmacsApp#toc5
>> (if (not (getenv "TERM_PROGRAM"))
>>    (setenv "PATH"
>>            (shell-command-to-string "source $HOME/.bashrc && printf $PATH")))
> 
> I did not download the emacs that you did and dig around so I am sorta half guessing.
> 
> Recently while dinking with rvm, I discovered that bash is not being started with --login.
> 
> Since the M-x shell has fewer parts in its path, I would suspect that the additional
> paths are being specified in /etc/profile.  Without bash thinking it is a login shell,
> /etc/profile is not being sourced.  One way is to start it with a - as the first character in
> arg0.  The other way is to start it with --login.

Dear Perry,

thanks a lot for helping. 

> 
> To explore if this is right: find where the parts for longer path are being set.  One
> choice is /etc/profile, another is your ~/.profile.  

sorry, I should have put this in earlier. So here is my /etc/profile [you still see the defaults write... from one of my trials]:

### /etc/profile ###

# System-wide .profile for sh(1)

if [ -x /usr/libexec/path_helper ]; then
	eval `/usr/libexec/path_helper -s`
        defaults write $HOME/.MacOSX/environment PATH "$PATH"
fi

if [ "${BASH-no}" != "no" ]; then
	[ -r /etc/bashrc ] && . /etc/bashrc
fi

###############

Here is ~/.profile [the last export is to call the same emacs when typing "emacs" in the Mac's terminal; otherwise, the preinstalled (old) emacs version is called]:

### ~/.profile ###

[ -f ~/.bashrc ] && . ~/.bashrc;

# MacPorts Installer addition on 2011-09-30_at_10:26:19: adding an appropriate PATH variable for use with MacPorts.
export PATH=$PATH:/opt/local/bin:/opt/local/sbin
# Finished adapting your PATH environment variable for use with MacPorts.

# make /Applications/Emacs.app/Contents/MacOS/emacs available when calling "emacs"
export PATH=/Applications/Emacs.app/Contents/MacOS/:$PATH

###############


> If these parts are in the profile but
> not in your .bashrc, then we are likely on the right track.

My .bashrc only contains some aliases and export LC_CTYPE=en_US.UTF-8 

> 
> If that is the case, then review explicit-bash-args.  You can customize them and add --login
> see if that works.  I'm a bit surprised this isn't done in the stock version of the code.

Thanks for the hint!!! I found this (see http://www-stat.wharton.upenn.edu/~buja/STAT-540/.emacs):
(setq explicit-bash-args (list "--login" "-i"))
I put it into .emacs and started emacs again. M-x shell now shows precisely the same PATH as in the terminal.
The only thing I'm wondering is: If this is really the perfect solution, why is it not mentioned on http://www.emacswiki.org/emacs/EmacsApp ? It seems to be much simpler than the other solutions posted, and (as I wrote) the other solutions even did not work for me. 

Cheers,

Marius


> 
> If you have a .profile,.bash_profile,
> or .bashrc, you can echo the path at the very top of each and open a new term window.  This will
> tell you where / how PATH is being set as it goes through your sequence of login scripts.
> 
> Hope this helps,
> pedz
> 




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs on Mac 10.7 (Lion): how to get PATH as in terminal?
  2011-10-23 21:57   ` Marius Hofert
@ 2011-10-23 23:15     ` Perry Smith
  2011-10-23 23:16       ` Marius Hofert
  0 siblings, 1 reply; 5+ messages in thread
From: Perry Smith @ 2011-10-23 23:15 UTC (permalink / raw)
  To: Marius Hofert; +Cc: Emacs help


On Oct 23, 2011, at 4:57 PM, Marius Hofert wrote:

> 
> On 2011-10-23, at 23:17 , Perry Smith wrote:
> 
>> 
>> On Oct 23, 2011, at 3:58 PM, Marius Hofert wrote:
>> 
>>> Hi,
>>> 
>>> I know this is an old problem, but I still couldn't figure it out with the tricks I found.
>>> I work with the emacs 23.3 on Mac OS X 10.7.2 (Lion), installed from http://emacsformacosx.com/
>>> When I open a shell with M-x shell and type echo $PATH, I get:
>>> /usr/bin:/bin:/usr/sbin:/sbin
>>> When I do the same in Mac's Terminal, I get:
>>> /Applications/Emacs.app/Contents/MacOS/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:/opt/local/bin:/opt/local/sbin
>>> 
>>> Question: How do I get the same PATH in emacs than in the terminal?
>>> 
>>> Trials:
>>> 
>>> 1) fixpath.el:
>>> (add-to-list 'load-path "~/.emacs.d/fixpath"); see https://svn.fsg.ulaval.ca/svn-pub/vgoulet/emacs-modified/macos/tags/Emacs-23.3-modified-3/fixpath.el
>>> (require 'fixpath)
>>> 
>>> 2) emacs wiki (http://www.emacswiki.org/emacs/EmacsApp#toc2)
>>> ;; add "defaults..." to /etc/profile:
>>> if [ -x /usr/libexec/path_helper ]; then
>>>       eval `/usr/libexec/path_helper -s`
>>>       defaults write $HOME/.MacOSX/environment PATH "$PATH"
>>> fi
>>> ;; add the following to .emacs:
>>> (add-to-list 'exec-path "/usr/bin")
>>> 
>>> 3) another solution posted on the emacs wiki page:
>>> ;; read in PATH from .bashrc (and add at least those directories)
>>> ;; see http://www.emacswiki.org/emacs/EmacsApp#toc5
>>> (if (not (getenv "TERM_PROGRAM"))
>>>   (setenv "PATH"
>>>           (shell-command-to-string "source $HOME/.bashrc && printf $PATH")))
>> 
>> I did not download the emacs that you did and dig around so I am sorta half guessing.
>> 
>> Recently while dinking with rvm, I discovered that bash is not being started with --login.
>> 
>> Since the M-x shell has fewer parts in its path, I would suspect that the additional
>> paths are being specified in /etc/profile.  Without bash thinking it is a login shell,
>> /etc/profile is not being sourced.  One way is to start it with a - as the first character in
>> arg0.  The other way is to start it with --login.
> 
> Dear Perry,
> 
> thanks a lot for helping. 
> 
>> 
>> To explore if this is right: find where the parts for longer path are being set.  One
>> choice is /etc/profile, another is your ~/.profile.  
> 
> sorry, I should have put this in earlier. So here is my /etc/profile [you still see the defaults write... from one of my trials]:
> 
> ### /etc/profile ###
> 
> # System-wide .profile for sh(1)
> 
> if [ -x /usr/libexec/path_helper ]; then
> 	eval `/usr/libexec/path_helper -s`
>        defaults write $HOME/.MacOSX/environment PATH "$PATH"
> fi
> 
> if [ "${BASH-no}" != "no" ]; then
> 	[ -r /etc/bashrc ] && . /etc/bashrc
> fi
> 
> ###############
> 
> Here is ~/.profile [the last export is to call the same emacs when typing "emacs" in the Mac's terminal; otherwise, the preinstalled (old) emacs version is called]:
> 
> ### ~/.profile ###
> 
> [ -f ~/.bashrc ] && . ~/.bashrc;
> 
> # MacPorts Installer addition on 2011-09-30_at_10:26:19: adding an appropriate PATH variable for use with MacPorts.
> export PATH=$PATH:/opt/local/bin:/opt/local/sbin
> # Finished adapting your PATH environment variable for use with MacPorts.
> 
> # make /Applications/Emacs.app/Contents/MacOS/emacs available when calling "emacs"
> export PATH=/Applications/Emacs.app/Contents/MacOS/:$PATH
> 
> ###############
> 
> 
>> If these parts are in the profile but
>> not in your .bashrc, then we are likely on the right track.
> 
> My .bashrc only contains some aliases and export LC_CTYPE=en_US.UTF-8 
> 
>> 
>> If that is the case, then review explicit-bash-args.  You can customize them and add --login
>> see if that works.  I'm a bit surprised this isn't done in the stock version of the code.
> 
> Thanks for the hint!!! I found this (see http://www-stat.wharton.upenn.edu/~buja/STAT-540/.emacs):
> (setq explicit-bash-args (list "--login" "-i"))
> I put it into .emacs and started emacs again. M-x shell now shows precisely the same PATH as in the terminal.
> The only thing I'm wondering is: If this is really the perfect solution, why is it not mentioned on http://www.emacswiki.org/emacs/EmacsApp ? It seems to be much simpler than the other solutions posted, and (as I wrote) the other solutions even did not work for me. 

Yea.  I bumped into this recently.  I'm surprised that it does not kick off the shell using "-sh" as argv[0] since some shells *only* grok that method of starting a login shell.

I guess the emacs developers do not see *shell* as a "login" shell.

LIke you, I'm surprised.

pedz




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Emacs on Mac 10.7 (Lion): how to get PATH as in terminal?
  2011-10-23 23:15     ` Perry Smith
@ 2011-10-23 23:16       ` Marius Hofert
  0 siblings, 0 replies; 5+ messages in thread
From: Marius Hofert @ 2011-10-23 23:16 UTC (permalink / raw)
  To: Perry Smith; +Cc: Emacs help

Dear Perry,

thanks a lot for your kind and very quick help.

Cheers,

Marius

On 2011-10-24, at 01:15 , Perry Smith wrote:

> 
> On Oct 23, 2011, at 4:57 PM, Marius Hofert wrote:
> 
>> 
>> On 2011-10-23, at 23:17 , Perry Smith wrote:
>> 
>>> 
>>> On Oct 23, 2011, at 3:58 PM, Marius Hofert wrote:
>>> 
>>>> Hi,
>>>> 
>>>> I know this is an old problem, but I still couldn't figure it out with the tricks I found.
>>>> I work with the emacs 23.3 on Mac OS X 10.7.2 (Lion), installed from http://emacsformacosx.com/
>>>> When I open a shell with M-x shell and type echo $PATH, I get:
>>>> /usr/bin:/bin:/usr/sbin:/sbin
>>>> When I do the same in Mac's Terminal, I get:
>>>> /Applications/Emacs.app/Contents/MacOS/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin:/opt/local/bin:/opt/local/sbin
>>>> 
>>>> Question: How do I get the same PATH in emacs than in the terminal?
>>>> 
>>>> Trials:
>>>> 
>>>> 1) fixpath.el:
>>>> (add-to-list 'load-path "~/.emacs.d/fixpath"); see https://svn.fsg.ulaval.ca/svn-pub/vgoulet/emacs-modified/macos/tags/Emacs-23.3-modified-3/fixpath.el
>>>> (require 'fixpath)
>>>> 
>>>> 2) emacs wiki (http://www.emacswiki.org/emacs/EmacsApp#toc2)
>>>> ;; add "defaults..." to /etc/profile:
>>>> if [ -x /usr/libexec/path_helper ]; then
>>>>      eval `/usr/libexec/path_helper -s`
>>>>      defaults write $HOME/.MacOSX/environment PATH "$PATH"
>>>> fi
>>>> ;; add the following to .emacs:
>>>> (add-to-list 'exec-path "/usr/bin")
>>>> 
>>>> 3) another solution posted on the emacs wiki page:
>>>> ;; read in PATH from .bashrc (and add at least those directories)
>>>> ;; see http://www.emacswiki.org/emacs/EmacsApp#toc5
>>>> (if (not (getenv "TERM_PROGRAM"))
>>>>  (setenv "PATH"
>>>>          (shell-command-to-string "source $HOME/.bashrc && printf $PATH")))
>>> 
>>> I did not download the emacs that you did and dig around so I am sorta half guessing.
>>> 
>>> Recently while dinking with rvm, I discovered that bash is not being started with --login.
>>> 
>>> Since the M-x shell has fewer parts in its path, I would suspect that the additional
>>> paths are being specified in /etc/profile.  Without bash thinking it is a login shell,
>>> /etc/profile is not being sourced.  One way is to start it with a - as the first character in
>>> arg0.  The other way is to start it with --login.
>> 
>> Dear Perry,
>> 
>> thanks a lot for helping. 
>> 
>>> 
>>> To explore if this is right: find where the parts for longer path are being set.  One
>>> choice is /etc/profile, another is your ~/.profile.  
>> 
>> sorry, I should have put this in earlier. So here is my /etc/profile [you still see the defaults write... from one of my trials]:
>> 
>> ### /etc/profile ###
>> 
>> # System-wide .profile for sh(1)
>> 
>> if [ -x /usr/libexec/path_helper ]; then
>> 	eval `/usr/libexec/path_helper -s`
>>       defaults write $HOME/.MacOSX/environment PATH "$PATH"
>> fi
>> 
>> if [ "${BASH-no}" != "no" ]; then
>> 	[ -r /etc/bashrc ] && . /etc/bashrc
>> fi
>> 
>> ###############
>> 
>> Here is ~/.profile [the last export is to call the same emacs when typing "emacs" in the Mac's terminal; otherwise, the preinstalled (old) emacs version is called]:
>> 
>> ### ~/.profile ###
>> 
>> [ -f ~/.bashrc ] && . ~/.bashrc;
>> 
>> # MacPorts Installer addition on 2011-09-30_at_10:26:19: adding an appropriate PATH variable for use with MacPorts.
>> export PATH=$PATH:/opt/local/bin:/opt/local/sbin
>> # Finished adapting your PATH environment variable for use with MacPorts.
>> 
>> # make /Applications/Emacs.app/Contents/MacOS/emacs available when calling "emacs"
>> export PATH=/Applications/Emacs.app/Contents/MacOS/:$PATH
>> 
>> ###############
>> 
>> 
>>> If these parts are in the profile but
>>> not in your .bashrc, then we are likely on the right track.
>> 
>> My .bashrc only contains some aliases and export LC_CTYPE=en_US.UTF-8 
>> 
>>> 
>>> If that is the case, then review explicit-bash-args.  You can customize them and add --login
>>> see if that works.  I'm a bit surprised this isn't done in the stock version of the code.
>> 
>> Thanks for the hint!!! I found this (see http://www-stat.wharton.upenn.edu/~buja/STAT-540/.emacs):
>> (setq explicit-bash-args (list "--login" "-i"))
>> I put it into .emacs and started emacs again. M-x shell now shows precisely the same PATH as in the terminal.
>> The only thing I'm wondering is: If this is really the perfect solution, why is it not mentioned on http://www.emacswiki.org/emacs/EmacsApp ? It seems to be much simpler than the other solutions posted, and (as I wrote) the other solutions even did not work for me. 
> 
> Yea.  I bumped into this recently.  I'm surprised that it does not kick off the shell using "-sh" as argv[0] since some shells *only* grok that method of starting a login shell.
> 
> I guess the emacs developers do not see *shell* as a "login" shell.
> 
> LIke you, I'm surprised.
> 
> pedz
> 





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-10-23 23:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-23 20:58 Emacs on Mac 10.7 (Lion): how to get PATH as in terminal? Marius Hofert
2011-10-23 21:17 ` Perry Smith
2011-10-23 21:57   ` Marius Hofert
2011-10-23 23:15     ` Perry Smith
2011-10-23 23:16       ` Marius Hofert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).