Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Last active April 12, 2024 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRadev/7856772c93c8956545dec8059283eea1 to your computer and use it in GitHub Desktop.
Save AndrewRadev/7856772c93c8956545dec8059283eea1 to your computer and use it in GitHub Desktop.
Add "ignored" status to statusline
" As an example, put it in the statusline (you should not do this here, just put the %{} in your config):
let &statusline = substitute(&statusline, '%f', '%f%{get(b:,"ignore_status","")}', '')
"
" get(b:, "ignore_status", "") -> Get the key "ignore_status" from the
" dictionary b: (all buffer-local variables), defaulting to ""
"
augroup IgnoreStatus
autocmd!
autocmd BufRead * call s:UpdateIgnoreStatus()
augroup END
function! s:UpdateIgnoreStatus() abort
" Note: only checks for .gitignore
let ignore_file = findfile('.gitignore', '.;')
if ignore_file == '' || !filereadable(ignore_file)
return
endif
for glob in readfile(ignore_file)
if glob !~ '^[^#]'
" It's a comment or blank line
continue
endif
" Some git patterns start with /
let glob = substitute(glob, '^/', '', '')
if expand('%') =~ glob2regpat(glob)
let b:ignore_status = " (ignored)"
return
endif
endfor
let b:ignore_status = ""
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment