@@ -52,4 +52,36 @@ if has("autocmd")
52
52
autocmd Filetype diff
53
53
\ highlight WhiteSpaceEOL ctermbg= red |
54
54
\ match WhiteSpaceEOL /\(^+.*\)\@<=\s\+$/
55
+
56
+ " When Git starts up, it prepends its libexec dir to PATH to allow it to
57
+ " find external commands.
58
+ "
59
+ " Thus, if Vim is invoked via a Git process (such as the contrib git-jump,
60
+ " or any other usage of GIT_EDITOR/VISUAL/EDITOR in Git commands, be they
61
+ " scripts or internals--with the exception of manually invoking the script
62
+ " yourself, without using Git: sh .../git-jump), $PATH will contain
63
+ " something like libexec/git-core.
64
+ "
65
+ " We don't generally want it in Vim's $PATH, though, as it is passed down
66
+ " to *all* subprocesses, including shells started with :terminal or
67
+ " :shell.
68
+ function s: fix_git_path () abort
69
+ let slash = exists (' +shellslash' ) && ! &shellslash ? ' \\' : ' /'
70
+ let git_core_base = printf (' %slib\%%(exec\)\?%sgit-core' , slash, slash)
71
+ " optimization: early return
72
+ if $PATH !~# git_core_base
73
+ return
74
+ endif
75
+ let path_sep = has (' win32' ) ? ' ;' : ' :'
76
+ let new_path = split ($PATH , path_sep)
77
+ \ - >filter ({_, d - > d !~# git_core_base..' $' })
78
+ \ - >join (path_sep)
79
+ let $PATH = new_path
80
+ endfunction
81
+
82
+ augroup fix_git_path
83
+ autocmd !
84
+ autocmd VimEnter * call s: fix_git_path ()
85
+ augroup end
86
+
55
87
endif " has(" autocmd " )
0 commit comments