blob: 3a4202736117d1e6729a3dce8f137981d514a9c1 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001" Vim plugin file
2" Purpose: Create a template for new bb files
3" Author: Ricardo Salveti <rsalveti@gmail.com>
4" Copyright: Copyright (C) 2008 Ricardo Salveti <rsalveti@gmail.com>
5"
6" This file is licensed under the MIT license, see COPYING.MIT in
7" this source distribution for the terms.
8"
9" Based on the gentoo-syntax package
10"
11" Will try to use git to find the user name and email
12
Andrew Geissler475cb722020-07-10 16:00:51 -050013if &compatible || v:version < 600 || exists("b:loaded_bitbake_plugin")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014 finish
15endif
16
17fun! <SID>GetUserName()
18 let l:user_name = system("git config --get user.name")
19 if v:shell_error
20 return "Unknown User"
21 else
22 return substitute(l:user_name, "\n", "", "")
23endfun
24
25fun! <SID>GetUserEmail()
26 let l:user_email = system("git config --get user.email")
27 if v:shell_error
Andrew Geissler475cb722020-07-10 16:00:51 -050028 return "unknown@user.org"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029 else
30 return substitute(l:user_email, "\n", "", "")
31endfun
32
33fun! BBHeader()
34 let l:current_year = strftime("%Y")
35 let l:user_name = <SID>GetUserName()
36 let l:user_email = <SID>GetUserEmail()
37 0 put ='# Copyright (C) ' . l:current_year .
38 \ ' ' . l:user_name . ' <' . l:user_email . '>'
39 put ='# Released under the MIT license (see COPYING.MIT for the terms)'
40 $
41endfun
42
43fun! NewBBTemplate()
Andrew Geissler475cb722020-07-10 16:00:51 -050044 if line2byte(line('$') + 1) != -1
45 return
46 endif
47
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048 let l:paste = &paste
49 set nopaste
50
51 " Get the header
52 call BBHeader()
53
54 " New the bb template
Andrew Geissler475cb722020-07-10 16:00:51 -050055 put ='SUMMARY = \"\"'
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 put ='HOMEPAGE = \"\"'
57 put ='LICENSE = \"\"'
58 put ='SECTION = \"\"'
59 put ='DEPENDS = \"\"'
60 put =''
61 put ='SRC_URI = \"\"'
62
63 " Go to the first place to edit
64 0
Andrew Geissler475cb722020-07-10 16:00:51 -050065 /^SUMMARY =/
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066 exec "normal 2f\""
67
68 if paste == 1
69 set paste
70 endif
71endfun
72
73if !exists("g:bb_create_on_empty")
74 let g:bb_create_on_empty = 1
75endif
76
77" disable in case of vimdiff
78if v:progname =~ "vimdiff"
79 let g:bb_create_on_empty = 0
80endif
81
82augroup NewBB
Andrew Geissler475cb722020-07-10 16:00:51 -050083 au BufNewFile,BufReadPost *.bb
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084 \ if g:bb_create_on_empty |
85 \ call NewBBTemplate() |
86 \ endif
87augroup END
88