Skip to content

Commit

Permalink
Add small script to place sign markers for Git, quickfix, etc
Browse files Browse the repository at this point in the history
Happy 2000th commit!

I started version-controlling my dotfiles sometime in 2007 if the
initial import timestamp is to be believed (and I think it is). I went
from keeping local flat files, to uploading flat files to my website
[1], to a brief experiment with RCS, to Subversion, then Mercurial, then
finally Git.

I'm not sure how old my dotfiles are. I've tried to look through
old/archived files for clues before. The earliest references I could
find is a blog post from 2005 [2] that says I've "long enjoyed" and an
old archive of `movein.sh` that has a timestamp of 2004 so around there
is probably a safe bet.

[1] https://github.com/whiteinge/dotfiles/blob/8d5ca5a9/.zshrc#L222
[2] https://www.eseth.org/2005/dotfiles.html
  • Loading branch information
whiteinge committed Oct 19, 2019
1 parent fc4f868 commit 882c3ac
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .vim/autoload/signs.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
call sign_define([
\ {'name' : 'GitAdd', 'text' : '+', 'texthl': 'Question'},
\ {'name' : 'GitDel', 'text' : '-', 'texthl': 'WarningMsg'},
\ {'name' : 'GitMod', 'text' : '=', 'texthl': 'Normal'},
\ {'name' : 'QfErr', 'text' : 'E', 'texthl': 'WarningMsg'},
\ {'name' : 'QfWarn', 'text' : 'W', 'texthl': 'WarningMsg'},
\ {'name' : 'QfGen', 'text' : '>', 'texthl': 'Normal'},
\ ])

" Return modified/deleted lines from Git.
fu! signs#GitChanges()
let l:curbuf = bufnr('%')
let l:curfile = expand('%')
let l:group = 'signs#git'

call sign_unplace(l:group, {'buffer' : l:curbuf})

let l:lines_changed = systemlist('git diff -U0 -- '.
\ shellescape(l:curfile) .' 2>/dev/null '
\ .'| diff-to-line-numbers | tail -n +2 | cut -f1')
\ ->map({i, x -> split(x, ' ')})
let l:g_items = {}
for [i_num, i_type] in l:lines_changed
if has_key(l:g_items, i_num)
let l:g_items[i_num] = 'GitMod'
else
if i_type == '+'
let l:g_items[i_num] = 'GitAdd'
else
let l:g_items[i_num] = 'GitDel'
endif
endif
endfor

let l:signs_array = l:g_items
\ ->items()
\ ->map({i, xs -> {
\ 'buffer': l:curbuf,
\ 'group': l:group,
\ 'lnum': xs[0],
\ 'name': xs[1],
\ }})

call sign_placelist(l:signs_array)
endfu

" Add any quickfix entries for the current file.
fu! signs#QfList()
let l:curbuf = bufnr('%')
let l:curfile = expand('%')
let l:group = 'signs#qf'

call sign_unplace(l:group)

let l:signs_array = getqflist()
\ ->map({i, x -> {
\ 'buffer': x.bufnr,
\ 'group': l:group,
\ 'lnum': x.lnum,
\ 'name': get({'E': 'QfErr', 'W': 'QfWarn'}, x.type, 'QfGen'),
\ }})

call sign_placelist(l:signs_array)
endfu
5 changes: 5 additions & 0 deletions .vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,11 @@ autocmd BufNewFile,BufReadPost *.md set filetype=markdown
""" Disable concealing for vim-json
let g:vim_json_syntax_conceal = 0

""" Autocommands for when to place signs
au BufReadPost * call signs#GitChanges()
au BufWritePost * call signs#GitChanges()
au QuickFixCmdPost * call signs#QfList()

""" Mapping to call DetectIndent
nmap <silent> <leader>i :1verbose DetectIndent<cr>
Expand Down

0 comments on commit 882c3ac

Please sign in to comment.