Fix issue when outside of git (no git config). Use F2 and :FT to avoid conflicts w/ official stdheader.vim
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
" By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ "
|
||||
" +#+#+#+#+#+ +#+ "
|
||||
" Created: 2013/06/15 12:45:56 by zaz #+# #+# "
|
||||
" Updated: 2021/10/26 08:32:41 by gbaconni ### lausanne.ch "
|
||||
" Updated: 2021/10/28 13:12:49 by gbaconni ### lausanne.ch "
|
||||
" "
|
||||
" **************************************************************************** "
|
||||
|
||||
@@ -60,97 +60,99 @@ let s:linelen = 80
|
||||
let s:marginlen = 5
|
||||
let s:contentlen = s:linelen - (3 * s:marginlen - 1) - strlen(s:asciiart[0])
|
||||
|
||||
function! s:trimlogin ()
|
||||
let l:trimlogin = strpart(systemlist('git config user.name')[0], 0, 9)
|
||||
if v:shell_error != 0 || strlen(l:trimlogin) == 0
|
||||
function s:trimlogin ()
|
||||
let l:login = systemlist('git config user.name')
|
||||
if v:shell_error == 0 && len(l:login) > 0
|
||||
let l:trimlogin = strpart(l:login[0], 0, 9)
|
||||
elseif exists("$USER")
|
||||
let l:trimlogin = strpart($USER, 0, 9)
|
||||
endif
|
||||
if strlen(l:trimlogin) == 0
|
||||
else
|
||||
let l:trimlogin = "marvin"
|
||||
endif
|
||||
return l:trimlogin
|
||||
endfunction
|
||||
|
||||
function! s:trimemail ()
|
||||
let l:trimemail = strpart(systemlist('git config user.email')[0], 0, s:contentlen - 5)
|
||||
if v:shell_error != 0 || strlen(l:trimemail) == 0
|
||||
function s:trimemail ()
|
||||
let l:email = systemlist('git config user.email')
|
||||
if v:shell_error == 0 && len(l:email) > 0
|
||||
let l:trimemail = strpart(l:email[0], 0, s:contentlen - 5)
|
||||
elseif exists("$MAIL")
|
||||
let l:trimemail = strpart($MAIL, 0, s:contentlen - 5)
|
||||
endif
|
||||
if strlen(l:trimemail) == 0
|
||||
else
|
||||
let l:trimemail = "marvin@student.42lausanne.ch"
|
||||
endif
|
||||
return l:trimemail
|
||||
endfunction
|
||||
|
||||
function! s:midgap ()
|
||||
function s:midgap ()
|
||||
return repeat(' ', s:marginlen - 1)
|
||||
endfunction
|
||||
|
||||
function! s:lmargin ()
|
||||
function s:lmargin ()
|
||||
return repeat(' ', s:marginlen - strlen(s:start))
|
||||
endfunction
|
||||
|
||||
function! s:rmargin ()
|
||||
function s:rmargin ()
|
||||
return repeat(' ', s:marginlen - strlen(s:end))
|
||||
endfunction
|
||||
|
||||
function! s:empty_content ()
|
||||
function s:empty_content ()
|
||||
return repeat(' ', s:contentlen)
|
||||
endfunction
|
||||
|
||||
function! s:left ()
|
||||
function s:left ()
|
||||
return s:start . s:lmargin()
|
||||
endfunction
|
||||
|
||||
function! s:right ()
|
||||
function s:right ()
|
||||
return s:rmargin() . s:end
|
||||
endfunction
|
||||
|
||||
function! s:bigline ()
|
||||
function s:bigline ()
|
||||
return s:start . ' ' . repeat(s:fill, s:linelen - 2 - strlen(s:start) - strlen(s:end)) . ' ' . s:end
|
||||
endfunction
|
||||
|
||||
function! s:logo1 ()
|
||||
function s:logo1 ()
|
||||
return s:left() . s:empty_content() . s:midgap() . s:asciiart[0] . s:right()
|
||||
endfunction
|
||||
|
||||
function! s:fileline ()
|
||||
function s:fileline ()
|
||||
let l:trimfile = strpart(fnamemodify(bufname('%'), ':t'), 0, s:contentlen)
|
||||
return s:left() . l:trimfile . repeat(' ', s:contentlen - strlen(l:trimfile)) . s:midgap() . s:asciiart[1] . s:right()
|
||||
endfunction
|
||||
|
||||
function! s:logo2 ()
|
||||
function s:logo2 ()
|
||||
return s:left() . s:empty_content() . s:midgap() .s:asciiart[2] . s:right()
|
||||
endfunction
|
||||
|
||||
function! s:coderline ()
|
||||
function s:coderline ()
|
||||
let l:contentline = "By: ". s:trimemail ()
|
||||
return s:left() . l:contentline . repeat(' ', s:contentlen - strlen(l:contentline)) . s:midgap() . s:asciiart[3] . s:right()
|
||||
endfunction
|
||||
|
||||
function! s:logo3 ()
|
||||
function s:logo3 ()
|
||||
return s:left() . s:empty_content() . s:midgap() .s:asciiart[4] . s:right()
|
||||
endfunction
|
||||
|
||||
function! s:dateline (prefix, logo)
|
||||
function s:dateline (prefix, logo)
|
||||
let l:date = strftime("%Y/%m/%d %H:%M:%S")
|
||||
let l:contentline = a:prefix . ": " . l:date . " by " . s:trimlogin ()
|
||||
return s:left() . l:contentline . repeat(' ', s:contentlen - strlen(l:contentline)) . s:midgap() . s:asciiart[a:logo] . s:right()
|
||||
endfunction
|
||||
|
||||
function! s:createline ()
|
||||
function s:createline ()
|
||||
return s:dateline("Created", 5)
|
||||
endfunction
|
||||
|
||||
function! s:updateline ()
|
||||
function s:updateline ()
|
||||
return s:dateline("Updated", 6)
|
||||
endfunction
|
||||
|
||||
function! s:emptyline ()
|
||||
function s:emptyline ()
|
||||
return s:start . repeat(' ', s:linelen - strlen(s:start) - strlen(s:end)) . s:end
|
||||
endfunction
|
||||
|
||||
function! s:filetype ()
|
||||
function s:filetype ()
|
||||
let l:file = fnamemodify(bufname("%"), ':t')
|
||||
|
||||
let s:start = '#'
|
||||
@@ -168,7 +170,7 @@ function! s:filetype ()
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:insert ()
|
||||
function s:insert ()
|
||||
call s:filetype ()
|
||||
|
||||
call append(0, "")
|
||||
@@ -185,7 +187,7 @@ function! s:insert ()
|
||||
call append (0, s:bigline())
|
||||
endfunction
|
||||
|
||||
function! s:update ()
|
||||
function s:update ()
|
||||
call s:filetype ()
|
||||
|
||||
let l:pattern = s:start . repeat(' ', 5 - strlen(s:start)) . "Updated: [0-9]"
|
||||
@@ -196,6 +198,6 @@ function! s:update ()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
command! Stdheader call s:insert ()
|
||||
nmap <F1> :Stdheader<CR>
|
||||
command FT call s:insert ()
|
||||
nmap <F2> :FT<CR>
|
||||
autocmd BufWritePre * call s:update ()
|
||||
|
||||
Reference in New Issue
Block a user