<commit_before>" MIT License. Copyright (c) 2017-2021 Cimbali et al
" Plugin: https://github.com/tpope/vim-fugitive
" vim: et ts=2 sts=2 sw=2

scriptencoding utf-8

if !airline#util#has_fugitive()
  finish
endif

function! s:ModifierFlags()
  return (exists("+autochdir") && &autochdir) ? ':p' : ':.'
endfunction

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') && exists('*fugitive#repo')
        if get(b:, 'fugitive_type', '') is# 'blob'
          let b:fugitive_name = fugitive#repo().translate(FugitivePath(@%, ''))
        endif
      elseif exists('b:git_dir') && !exists('*fugitive#repo')
        let buffer = fugitive#buffer()
        if buffer.type('blob')
          let b:fugitive_name = buffer.repo().translate(buffer.path('/'))
        endif
      endif
    catch
    endtry
  endif

  let fmod = s:ModifierFlags()
  if empty(b:fugitive_name)
    if empty(bufname('%'))
      return &buftype ==# 'nofile' ? '[Scratch]' : '[No Name]'
    endif
    return fnamemodify(bufname('%'), fmod)
  else
    return fnamemodify(b:fugitive_name, fmod). " [git]"
  endif
endfunction

function! s:sh_autocmd_handler()
  if exists('#airline')
    unlet! b:fugitive_name
  endif
endfunction

function! airline#extensions#fugitiveline#init(ext)
  if exists("+autochdir") && &autochdir
    " 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 * call s:sh_autocmd_handler()<commit_msg>[fix] issue #2338 add check airline_stl_path_style's flag and pathshortln api<commit_after>" MIT License. Copyright (c) 2017-2021 Cimbali et al
" Plugin: https://github.com/tpope/vim-fugitive
" vim: et ts=2 sts=2 sw=2

scriptencoding utf-8

if !airline#util#has_fugitive()
  finish
endif

function! s:ModifierFlags()
  return (exists("+autochdir") && &autochdir) ? ':p' : ':.'
endfunction

function! airline#extensions#fugitiveline#bufname() abort
  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') && exists('*fugitive#repo')
        if get(b:, 'fugitive_type', '') is# 'blob'
          let b:fugitive_name = fugitive#repo().translate(FugitivePath(@%, ''))
        endif
      elseif exists('b:git_dir') && !exists('*fugitive#repo')
        let buffer = fugitive#buffer()
        if buffer.type('blob')
          let b:fugitive_name = buffer.repo().translate(buffer.path('/'))
        endif
      endif
    catch
    endtry
  endif

  let fmod = s:ModifierFlags()
  if empty(b:fugitive_name)
    if empty(bufname('%'))
      return &buftype ==# 'nofile' ? '[Scratch]' : '[No Name]'
    endif
    return fnamemodify(bufname('%'), fmod)
  else
    return fnamemodify(b:fugitive_name, fmod). " [git]"
  endif
endfunction

function! s:sh_autocmd_handler()
  if exists('#airline')
    unlet! b:fugitive_name
  endif
endfunction

function! airline#extensions#fugitiveline#init(ext) abort
  if exists("+autochdir") && &autochdir
    " if 'acd' is set, vim-airline uses the path section, so we need to redefine this here as well
    if get(g:, 'airline_stl_path_style', 'default') ==# 'short'
      call airline#parts#define_raw('path', '%<%{pathshorten(airline#extensions#fugitiveline#bufname())}%m')
    else
      call airline#parts#define_raw('path', '%<%{airline#extensions#fugitiveline#bufname()}%m')
    endif
  else
    if get(g:, 'airline_stl_path_style', 'default') ==# 'short'
      call airline#parts#define_raw('file', '%<%{pathshorten(airline#extensions#fugitiveline#bufname())}%m')
    else
      call airline#parts#define_raw('file', '%<%{airline#extensions#fugitiveline#bufname()}%m')
    endif
  endif
  autocmd ShellCmdPost,CmdwinLeave * call s:sh_autocmd_handler()
{'fraction_non_alphanumeric': 0.15714959886739027, 'fraction_numerical': 0.0066068900424728644, 'mean_word_length': 4.31203007518797, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7649572', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1524, 'n_words': 306}