aboutsummaryrefslogtreecommitdiff
path: root/.vim/autoload/airline/extensions/fugitiveline.vim
blob: 5dab99514fbd48fcb88b116992a0fd56b719de9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
" MIT License. Copyright (c) 2017-2018 Cimbali et al
" vim: et ts=2 sts=2 sw=2

scriptencoding utf-8

if !airline#util#has_fugitive()
  finish
endif


if exists("+autochdir") && &autochdir == 1
  let s:fmod = ':p'
else
  let s:fmod = ':.'
endif

function! airline#extensions#fugitiveline#bufname()
  if !exists('b:fugitive_name')
    let b:fugitive_name = ''
    try
      if bufname('%') =~? '^fugitive:' && exists('*FugitiveReal')
        let b:fugitive_name = FugitiveReal(bufname('%'))
      elseif exists('b:git_dir')
        let buffer = fugitive#buffer()
        if buffer.type('blob')
          let b:fugitive_name = buffer.repo().translate(buffer.path('/'))
        endif
      endif
    catch
    endtry
  endif

  if empty(b:fugitive_name)
    return fnamemodify(bufname('%'), s:fmod)
  else
    return fnamemodify(b:fugitive_name, s:fmod)
  endif
endfunction

function! airline#extensions#fugitiveline#init(ext)
  if exists("+autochdir") && &autochdir == 1
    " if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well
    call airline#parts#define_raw('path', '%<%{airline#extensions#fugitiveline#bufname()}%m')
  else
    call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m')
  endif
  autocmd ShellCmdPost,CmdwinLeave * unlet! b:fugitive_name
  autocmd User AirlineBeforeRefresh unlet! b:fugitive_name
endfunction