Discussion:
Shelling out to cygwin bash from Windows vim
(too old to reply)
AndyHancock
2012-09-01 23:27:17 UTC
Permalink
This problem dogged me for many years, and I finally hunkered down to
chase it down.

Here is the solution that I found works for me:

"set shell=c:\cygwin\bin\bash.exe\ -i
"Won't always find ~/.bashrc cuz depending on how vim is launched,
"~ doesn't always resolve to c:/cygwin/home/$USERNAME
"let &shell='c:\cygwin\bin\bash.exe\ --rcfile c:\cygwin\home\' .
" \ $USERNAME . '\.bashrc'
"Backslashes are hated by bash. Also needs -i to ensure bash is
"interactive so that .bashrc is sourced
let &shell='c:\cygwin\bin\bash.exe --rcfile c:/cygwin/home/' .
\ $USERNAME . '/.bashrc -i'
" Depending on how vim is launched, c:/cygwin/home/$USERNAME
" will sometimes be equivalent to ~. If so, then it will be
" replaced by ~ in &shell.

Thanks to all those who helped on the unix, bash, cygwin, and vim
forums.
AndyHancock
2012-09-02 00:00:09 UTC
Permalink
Sorry, what I posted was completely lacking in context. The shell
option has to be set in such a way that bash sources .bashrc and picks
up the aliases, function definitions, and most importantly, the PATH.

To maintain common vimrc files for Windows & Cygwin installs of vim
across multiple computers, I stick a pair conditional if tests around
the code that sets the shell option only if the executing vim is a
Windows install on an computer that is known to have cygwin.

if (
\ hostname()=="host1withCygwin" ||
\ hostname()=="host2withCygwin" ||
\ hostname()=="host3withCygwin"
\ )

if has("win32") || has("win64")

"set shell=c:\cygwin\bin\bash.exe\ -i
"Won't always find ~/.bashrc cuz depending on how vim is
"launched, ~ doesn't always resolve to
"c:/cygwin/home/$USERNAME
"let &shell='c:\cygwin\bin\bash.exe ' .
" \ '--rcfile c:\cygwin\home\' . $USERNAME . '\.bashrc'
"Backslashes are hated by bash. Also needs -i to
"ensure bash is interactive so that .bashrc is
"sourced
let &shell='c:\cygwin\bin\bash.exe ' .
\ --rcfile c:/cygwin/home/' . $USERNAME . '/.bashrc -i'
" Depending on how vim is launched,
" c:/cygwin/home/$USERNAME will sometimes be equivalent
to
" ~. If so, then it will be replaced by ~ in &shell.

endif

endif

Though the above works fine for me, I'm sure both if for checking the
host can be eliminated by simply checking for the existence of c:/
cygwin/$USERNAME/.bashrc. Unless some machines with cygwin use a
different path or drive for user home directories. Or unless there
are specific machines on which the user does not want to be able to
shell out in the above manner. For example, I haven't tested what
happens if the user relies on a system wide bashrc, and hence doesn't
have a bashrc in his/her home directory.

Loading...