summaryrefslogtreecommitdiffstats
path: root/bitbake/contrib/vim/plugin/newbb.vim
blob: 3019c855c0fd50e8a3ea16e5e60e53722aed3fac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
" Vim plugin file
" Purpose:	Create a template for new bb files
" Author:	Ricardo Salveti <rsalveti@gmail.com>
" Copyright:	Copyright (C) 2008 Ricardo Salveti <rsalveti@gmail.com>
"
" This file is licensed under the MIT license, see COPYING.MIT in
" this source distribution for the terms.
"
" Based on the gentoo-syntax package
"
" Will try to use git to find the user name and email

if &compatible || v:version < 600
    finish
endif

fun! <SID>GetUserName()
    let l:user_name = system("git config --get user.name")
    if v:shell_error
        return "Unknown User"
    else
        return substitute(l:user_name, "\n", "", "")
endfun

fun! <SID>GetUserEmail()
    let l:user_email = system("git config --get user.email")
    if v:shell_error
        return "unknow@user.org"
    else
        return substitute(l:user_email, "\n", "", "")
endfun

fun! BBHeader()
    let l:current_year = strftime("%Y")
    let l:user_name = <SID>GetUserName()
    let l:user_email = <SID>GetUserEmail()
    0 put ='# Copyright (C) ' . l:current_year .
                \ ' ' . l:user_name . ' <' . l:user_email . '>'
    put ='# Released under the MIT license (see COPYING.MIT for the terms)'
    $
endfun

fun! NewBBTemplate()
    let l:paste = &paste
    set nopaste
    
    " Get the header
    call BBHeader()

    " New the bb template
    put ='DESCRIPTION = \"\"'
    put ='HOMEPAGE = \"\"'
    put ='LICENSE = \"\"' 
    put ='SECTION = \"\"'
    put ='DEPENDS = \"\"'
    put ='PR = \"r0\"'
    put =''
    put ='SRC_URI = \"\"'

    " Go to the first place to edit
    0
    /^DESCRIPTION =/
    exec "normal 2f\""

    if paste == 1
        set paste
    endif
endfun

if !exists("g:bb_create_on_empty")
    let g:bb_create_on_empty = 1
endif

" disable in case of vimdiff
if v:progname =~ "vimdiff"
    let g:bb_create_on_empty = 0
endif

augroup NewBB
    au BufNewFile *.bb
                \ if g:bb_create_on_empty |
                \    call NewBBTemplate() |
                \ endif
augroup END