blob: 75b20f021e99e8c55ebfb2b37b510ca5ba2dafac [file] [log] [blame]
Bram Moolenaar3577c6f2008-06-24 21:16:56 +00001" Vim filetype plugin
2" Language: generic git output
Bram Moolenaar5c736222010-01-06 20:54:52 +01003" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
Bram Moolenaarc08ee742019-12-05 22:47:25 +01004" Last Change: 2019 Dec 05
Bram Moolenaar3577c6f2008-06-24 21:16:56 +00005
6" Only do this when not done yet for this buffer
7if (exists("b:did_ftplugin"))
Bram Moolenaar7a329912010-05-21 12:05:36 +02008 finish
Bram Moolenaar3577c6f2008-06-24 21:16:56 +00009endif
10let b:did_ftplugin = 1
11
12if !exists('b:git_dir')
Bram Moolenaarc08ee742019-12-05 22:47:25 +010013 if expand('%:p') =~# '[\/]\.git[\/]modules[\/]\|:[\/][\/]\|^\a\a\+:'
Bram Moolenaar53bfca22012-04-13 23:04:47 +020014 " Stay out of the way
Bram Moolenaar89bcfda2016-08-30 23:26:57 +020015 elseif expand('%:p') =~# '[\/]\.git[\/]worktrees'
16 let b:git_dir = matchstr(expand('%:p'),'.*\.git[\/]worktrees[\/][^\/]\+\>')
Bram Moolenaar53bfca22012-04-13 23:04:47 +020017 elseif expand('%:p') =~# '\.git\>'
Bram Moolenaar7a329912010-05-21 12:05:36 +020018 let b:git_dir = matchstr(expand('%:p'),'.*\.git\>')
19 elseif $GIT_DIR != ''
20 let b:git_dir = $GIT_DIR
21 endif
22 if (has('win32') || has('win64')) && exists('b:git_dir')
23 let b:git_dir = substitute(b:git_dir,'\\','/','g')
24 endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000025endif
26
27if exists('*shellescape') && exists('b:git_dir') && b:git_dir != ''
Bram Moolenaar7a329912010-05-21 12:05:36 +020028 if b:git_dir =~# '/\.git$' " Not a bare repository
29 let &l:path = escape(fnamemodify(b:git_dir,':h'),'\, ').','.&l:path
30 endif
31 let &l:path = escape(b:git_dir,'\, ').','.&l:path
32 let &l:keywordprg = 'git --git-dir='.shellescape(b:git_dir).' show'
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000033else
Bram Moolenaar7a329912010-05-21 12:05:36 +020034 setlocal keywordprg=git\ show
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000035endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010036if has('gui_running')
37 let &l:keywordprg = substitute(&l:keywordprg,'^git\>','git --no-pager','')
38endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000039
40setlocal includeexpr=substitute(v:fname,'^[^/]\\+/','','')
41let b:undo_ftplugin = "setl keywordprg< path< includeexpr<"