From: Earnie <ea...@us...> - 2011-03-29 12:55:30
|
LRN wrote: > msysCORE's default /etc/profile ends with this line: > cd "$HOME" > The /etc/profile file is only used when --login is specified and sh without --login remains in the current directory. > Would it be a good idea to make it conditional (i.e. profile only cds > into $HOME if some convolutely-named environment variable is set to > something non-empty)? If you want users to go into $HOME by default, you > might as well set the right env.variable in msys.bat (which is, i think, > what 95% of msys users run to get into msys). It is *NIX natural to start in the $HOME directory. Actually I thought MSYS itself set the environment variable if it was empty in the startup code but it must be the profile file that does that. I know that /etc/profile came after I gave maintenance to Cesar and that some of what became /etc/profile was in msys.bat. > cd'ing into $HOME prevents external processes (non-msys processes) from > running msys shell in login mode (well, it doesn't really prevent that - > but current directory changes, and if an external process passed a > command along (it usually does), it gets executed in the wrong > directory). Running in non-login mode is not a good option, because it > skips /etc/profile - which means that the resulting shell doesn't have > correct PATH, HOME, MAKE_MODE variables etc. > The --login mode is supposed to go to the $HOME directory and external commands shouldn't be using the switch unless the external command wants to ensure that the profile files are executed and then must deal with the fallout of things like a cd happening. There is nothing that prevents the end user from adding a cd to /etc/profile or his local ~/.profile for that matter. > ALSO > > Msys sets $HOME (if empty) to "/home/$LOGNAME" Actually this is /etc/profile and /etc/profile also ensures the directory exists. > Msys^Wmingw-git sets $HOME (if empty) to "$HOMEDRIVE$HOMEPATH" Yeck, C:\ is what that becomes on my system. > or (if > that is empty or doesn't exist) to "$USERPROFILE", and then msysizes it And this is c:\Documents and Settings\Earnie Boyd on my system, not a good place for $HOME files to be placed. > by setting $HOME to "$(cd "$HOME" ; pwd)" > Personally i like the way it is in msys (/home/*/ makes it close, simple > and easy), but msys^Wmingw-git has a point as well - if someone has > multiple msys installations in space (i.e. simultaneously) and/or time > (over the course of time), that someone might value the fact that the > contents of the $HOME directory do not change from msys to msys. Then set the HOME variable in the windows environment is my reply. It will be propagated and POSIXfied in MSYS at startup. > Msys^Wmingw-git also do it because they have some kind of shell > extension that `runs git-bash from here' and requires CD to be preserved. > What do you think? I think --login is supposed to go to $HOME and that will not change. I think that if git-bash needs to execute the shell and leave the CD as it was before --login it should execute ``cd -'' after starting. And git-bash can also specify --noprofile --rcfile /etc/git-bash.rc to overcome the issue but testing leads to heartbreak, more research on this one. Git-bash should never rely on its CWD to be where it started since the user can do silly things. > > ALSO > > /etc/profile is overwritten by each new msysCORE upgrade, AFAIU. How > does one make global (per-user changes can be made with per-user shell > config, i think) shell changes in such circumstances? Some packages > might want to change it as well. A possible way to do that is to write > these changes (by these packages) into /etc/profile, but make them > conditional. I guess it depends on the nature of these changes. But > releasing a new msysCORE version just because something in /etc/profile > has to be changed is definitely not good. > You create /etc/profile.d/myprofile.sh and voila, you have it; at least with the current version of MSYS and myprofile.sh can be any *.sh file. -- Earnie -- http://www.for-my-kids.com |