Skip to content

Commit ff2c12e

Browse files
authored
Merge pull request #26 from mnabila/author_from_git
feat(header): add option to auto-populate author name from git config
2 parents 9c3ba50 + 1a47bb0 commit ff2c12e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The script comes with the following defaults:
4949
use_block_header = true,
5050
copyright_text = nil,
5151
license_from_file = false,
52+
author_from_git = false,
5253
}
5354
```
5455

@@ -82,6 +83,7 @@ require("header").setup({
8283
"All rights reserved."
8384
},
8485
license_from_file = false,
86+
author_from_git = false,
8587
})
8688
```
8789

lua/header.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ header.config = {
1818
use_block_header = true,
1919
copyright_text = nil,
2020
license_from_file = false,
21+
author_from_git = false,
2122
}
2223

2324
header.constants = {
@@ -333,6 +334,13 @@ local function prepare_headers(callback)
333334
-- Format modified_time as a human-readable string
334335
creation_date = os.date(header.config.date_created_fmt, creation_date)
335336

337+
if header.config.author_from_git then
338+
local result = vim.fn.systemlist("git config user.name")
339+
if vim.v.shell_error == 0 and #result > 0 then
340+
header.config.author = result[1]
341+
end
342+
end
343+
336344
local headers = {}
337345
if header.config.file_name then
338346
table.insert(headers, header.constants.file_name .. " " .. file_name)

0 commit comments

Comments
 (0)