Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell fugitive my path to Git on Windows?

Tags:

git

vim

windows

cmd

So I downloaded the fugitive plugin for Vim and try to get it running on my Windows 7 machine.

I don't have the path to git.exe in my %PATH% and I don't want to add it since issues could arise doing such.

My Git is installed at C:\Program Files (x86)\Git\. There's a config option for fugitive where I could tell my path to git.exe (g:fugitive_git_executable).

I've tried several flavours:

  1. 'C:/Program Files (x86)/Git/cmd/git.exe'
  2. 'C:\Program Files (x86)\Git\cmd\git.exe'
  3. "C:\Program Files (x86)\Git\cmd\git.exe"
  4. "C:\\Program Files (x86)\\Git\\cmd\\git.exe"

But none is working. Seems like in 1, 2, 4, there's a problem with the brackets in the path. The resulting call of :Git status is

C:\WINDOWS\system32\cmd.exe /c (C:\Program Files ^(x86^)\Git\cmd\git.exe status)

and the cmd window complains that "\Git\cmd\git.exe" could not be processed (translated from German).

How do I specify the path to git.exe so that I don't have to expand my $PATH variable?

Or more general: when using the system command in Vim, how do I call programs that are located under 'C:\Program Files (x86)\?

like image 953
eckes Avatar asked Sep 16 '14 08:09

eckes


2 Answers

In your vimrc, add something like the following:

if has('win32')
    let $PATH .= ';' . 'C:/Program Files (x86)/Git/bin'
endif

This won't affect the value of %PATH% outside of Vim.

Alternatively, to get Fugitive to work as advertised, you'll have to patch it a bit. In s:Git() replace

call s:ExecuteInTree('!'.git.' '.cmd)

with

if has('win32')
    call s:ExecuteInTree('!"'.git.' '.cmd.'"')
else
    call s:ExecuteInTree('!'.git.' '.cmd)
endif

and then put quotation marks around the path to the executable in your vimrc:

let g:fugitive_git_executable = '"C:/Program Files (x86)/Git/bin/git"'

(See correct quoting for cmd.exe for multiple arguments.)

You might want to get in touch with the maintainer. I'd be surprised if this issue hasn't cropped up before.

I just modify $PATH. Some programs require $PATH to be set correctly, anyhow.

(Plus: @echristopherson's solution is perfectly viable, but it's annoying to have to resort to that in the 21st Century.)

like image 179
1983 Avatar answered Oct 17 '22 16:10

1983


The standard directory C:\Program Files (x86) can be abbreviated to C:\Progra~2*. This kind of shortened name is how long filenames or filenames with spaces in them were actually represented on FAT filesystems (which internally are restricted to filenames of eight base characters and three extension characters) from Windows 95 on, but it's still supported for compatibility in modern Windows systems using NTFS, at least in specific cases like the Program Files (x86) folder.

C:\Program Files is, similarly, C:\Progra~1.

* In Vimscript the backslashes should be changed to slashes unless they are either doubled up or enclosed in single quotes.

like image 22
echristopherson Avatar answered Oct 17 '22 15:10

echristopherson