Skip to content

git-extra(vimrc): adjust $PATH to remove Git's libexec #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions git-extra/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pkgbase="mingw-w64-${_realname}"
pkgname=($_realname
"${MINGW_PACKAGE_PREFIX}-${_realname}")
_ver_base=1.1
pkgver=1.1.653.48e2403b3
pkgver=1.1.654.aca5df34e
pkgrel=1
pkgdesc="Git for Windows extra files"
arch=('any')
Expand Down Expand Up @@ -62,7 +62,7 @@ source=('inputrc'
'git-askpass.h'
'git-askpass.rc')
sha256sums=('8ed76d1cb069ac8568f21c431f5e23caebea502d932ab4cdff71396f4f0d5b72'
'e36a3b93b8a33b0a74619f2449ed6d56ed54e4e2938b97070bce4926f1f44054'
'7736786309a58112b7ac60627b3df049eb5eac3e0627c364939277477aaa03f1'
'640d04d2a2da709419188a986d5e5550ad30df23c7ea9be1a389c37a6b917994'
'17c90698d4dd52dd9f383e72aee54ecea0f62520baf56722de5c83285507c0d9'
'3cd83627f1d20e1108533419fcf33c657cbcf777c3dc39fa7f13748b7d63858a'
Expand Down
32 changes: 32 additions & 0 deletions git-extra/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,36 @@ if has("autocmd")
autocmd Filetype diff
\ highlight WhiteSpaceEOL ctermbg=red |
\ match WhiteSpaceEOL /\(^+.*\)\@<=\s\+$/

" When Git starts up, it prepends its libexec dir to PATH to allow it to
" find external commands.
"
" Thus, if Vim is invoked via a Git process (such as the contrib git-jump,
" or any other usage of GIT_EDITOR/VISUAL/EDITOR in Git commands, be they
" scripts or internals--with the exception of manually invoking the script
" yourself, without using Git: sh .../git-jump), $PATH will contain
" something like libexec/git-core.
"
" We don't generally want it in Vim's $PATH, though, as it is passed down
" to *all* subprocesses, including shells started with :terminal or
" :shell.
function s:fix_git_path() abort
let slash = exists('+shellslash') && !&shellslash ? '\\' : '/'
let git_core_base = printf('%slib\%%(exec\)\?%sgit-core', slash, slash)
" optimization: early return
if $PATH !~# git_core_base
return
endif
let path_sep = has('win32') ? ';' : ':'
let new_path = split($PATH, path_sep)
\ ->filter({_, d -> d !~# git_core_base..'$' })
\ ->join(path_sep)
let $PATH = new_path
endfunction

augroup fix_git_path
autocmd!
autocmd VimEnter * call s:fix_git_path()
augroup end

endif " has("autocmd")