X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,TW_RX,TW_YG,TW_ZG,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Date: Mon, 6 Feb 2012 14:51:11 -0800 From: Gary Johnson To: cygwin AT cygwin DOT com Subject: Re: Environment variable mixing when starting non-cygwin GVIM from within cygwin terminal? Message-ID: <20120206225111.GC10856@phoenix> Mail-Followup-To: cygwin AT cygwin DOT com References: <4F30405C DOT 9030309 AT gmail DOT com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4F30405C.9030309@gmail.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On 2012-02-06, reckoner wrote: > Hi, > > I usually start the non-cygwin gvim.exe via the rxvt cygwin console > doing something like: > > % gvim filename.py > > the problem is that, when inside GVIM, when I do: > > :py print os.environ['PATH'] > > I see a lot of cygwin paths which messes up the Python path that GVIM > wants to use. Is there a way to start gvim.exe so that this doesn't > happen? Note that I can avoid this situation by starting GVIM in a > plain vanilla CMD window, or from a standard window shortcut, instead > of using the cygwin terminal. > > This is on Windows XP Professional Ver 5.1 Build 2600 Service Pack 3. I've run into a number of issues starting Windows gvim from the Cygwin bash prompt or from within Cygwin vim, so I wrote a script which I put in /usr/local/bin/gvim to give Windows gvim an environment closer to the one it gets when started by Windows. You may need to use cygpath to convert other paths to a form usable by other programs that gvim may invoke, such as Python. Regards, Gary ------------------------------------------------------------------------------ #!/bin/sh # Remove Vim variables from the environment # # Vim sets the MYVIMRC, VIM and VIMRUNTIME variables and exports them to the # environment of any children it runs. Vim also checks these variables when # it starts and uses their values instead of redetermining the values from # scratch. This causes a problem when a Cygwin vim invokes gvim or another # program that launches gvim, such as Firefox. That gvim will get the # environment that its parent program was started with. If that environment # includes VIM and VIMRUNTIME, the gvim for Windows will try to find its # runtime files using Cygwin path names, which will fail. # unset MYVIMRC VIM VIMRUNTIME # Remove HOME from the environment # # Cygwin sets HOME to a value different from what Windows programs see. Vim # will reconstruct the proper value from HOMEDRIVE and HOMEPATH. # unset HOME # Restore other environment variables to their Windows defaults # # Note (2011-08-12): A better way to get the original values of TEMP and TMP # might be this, from the cygwin list: # # zgyg wrote: # > Windows stores the environment variables in the registry, under # > `HKEY_CURRENT_USER\Environment' and # > `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session # > Manager\Environment'. You can access these through /proc/registry in # > cygwin. For an example see the PRINTER setting in /etc/profile. # # That is an excellent note. Documentation can be found at # http://www.cygwin.com/cygwin-ug-net/using-specialnames.html. The regtool # might be also useful in this regard. # TEMP="$(cygpath -d --homeroot)\\${USERNAME}\LOCALS~1\Temp" TMP="$TEMP" cygdirs="/usr/local/bin:/usr/bin" PATH=${PATH##${cygdirs}:}:${cygdirs} unset cygdirs # Use Luc Hermitte's cyg-wrapper.sh script if available. # (http://hermitte.free.fr/vim/idx-all.php) if type cyg-wrapper.sh > /dev/null 2>&1 then # Re --binary-opt=...,-u,...: The argument to the -u option is a file # name, but a few values are special, e.g., NONE, and cyg-wrapper.sh # doesn't know that and converts the special values to Windows path names. # Since I use -u for only NONE and relative file names, I tell # cyg-wrapper.sh that the argument is not a file name. exec cyg-wrapper.sh "C:/Progra~1/Vim/vim73/gvim.exe" \ --binary-opt=-c,--cmd,-T,-t,-u,--servername,--remote-send,--remote-expr \ --fork=2 "$@" else # To allow for non-filename or relative filename arguments, use this for # now. # exec "/cygdrive/c/Program Files/Vim/vim73/gvim" "$@" & fi -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple