This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Environment variable mixing when starting non-cygwin GVIM from within cygwin terminal?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]