Some things that may help you.
Keep in mind that my solution caters to both being in a /mnt/*
path, and also being in my symlink path.
When you make a symbolic link, as in: ln -s /mnt/c/Users/bar $HOME/bar
and cd
into that, the $PWD
will reflect that.
This simply uses git.exe
or /usr/bin/git
depending on your $PWD
# This is for your .bashrc
## checks to see if we are in a windows or linux dir
function isWinDir {
case $PWD/ in
/mnt/*) return $(true);;
## if you like to use a symlink to /mnt/c/Users/bar you gotta do this..
/home/foo/bar/*) return $(true);;
*) return $(false);;
esac
}
## wrap the git command to either run windows git or linux
function git {
if isWinDir
then
git.exe "$@"
else
/usr/bin/git "$@"
fi
}
This is a technique to clean up the path slashes and use git.exe
if in /mnt
(or symlink)
" Put this in .vim/after/plugin/fugitive.vim
function! StartsWith(longer, shorter) abort
return a:longer[0:len(a:shorter)-1] ==# a:shorter
endfunction
function! InWindows() abort
" /home/jtm/jtm is a symlink to /mnt/c/Users/jtm
return StartsWith($PWD, '/mnt') || StartsWith($PWD, '/home/jtm/jtm')
endfunction
function! FugitiveGitPath(path) abort
if InWindows()
let g:fugitive_git_executable = '/mnt/c/PROGRA~1/Git/cmd/git.exe'
return substitute(a:path, '^/mnt/\(\a\)/', '\1:/', '')
endif
return a:path
endfunction
function! FugitiveVimPath(path) abort
if InWindows()
return substitute(a:path, '^\(\a\):/', '/mnt/\1/', '')
endif
return a:path
endfunction