-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitinfo.lua
38 lines (30 loc) · 1.05 KB
/
gitinfo.lua
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
function Str(elem)
local findresult = string.find(elem.text, "{{describegitref_", 1, true)
if findresult ~= nil then
local gitref = string.match(elem.text, "_(.*)}}")
local handle
handle = io.popen("git name-rev --name-only "..gitref)
local gitrefname = handle:read("*a")
gitrefname = string.gsub(gitrefname,"\n$","")
gitrefname = string.gsub(gitrefname,"^tags/","")
handle:close()
handle = io.popen("git rev-parse "..gitref)
local gitcommit = handle:read("*a")
gitcommit = string.gsub(gitcommit,"\n$","")
handle:close()
local handle = io.popen("git log -1 --pretty=format:'%cs' "..gitref)
local gitdate = handle:read("*a")
gitdate = string.gsub(gitdate,"\n$","")
handle:close()
return {
pandoc.Str(gitrefname),
pandoc.Space(),
pandoc.Str("("..gitcommit.."),"),
pandoc.Space(),
pandoc.Str(gitdate)
}
else
return elem
end
end
-- vim:sw=4:ts=4:et:ai: