-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add small script to place sign markers for Git, quickfix, etc
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
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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