Last active
April 12, 2024 16:39
-
-
Save AndrewRadev/7856772c93c8956545dec8059283eea1 to your computer and use it in GitHub Desktop.
Add "ignored" status to statusline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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