-
Notifications
You must be signed in to change notification settings - Fork 24
/
gitinfowdx.lua
96 lines (90 loc) · 4.44 KB
/
gitinfowdx.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
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
86
87
88
89
90
91
92
93
94
95
96
-- gitinfowdx.lua
local result_true = "☑️"
local result_false = "❎"
local out = '(' .. result_true .. '/' .. result_false .. ')'
local fields = { -- field name, field type, command, strip newline, sort order
{"Subject", 8, "git log -1 --pretty=format:%s", false, 1},
{"Body", 8, "git log -1 --pretty=format:%b", false, 1},
{"Commit hash", 8, "git log -1 --pretty=format:%H", false, 1},
{"Committer name", 8, "git log -1 --pretty=format:%cn", false, 1},
{"Committer email", 8, "git log -1 --pretty=format:%ce", false, 1},
{"Сommitter date", 8, "git log -1 --pretty=format:%cd --date=format:'%d.%m.%Y %H:%M'", false, 1},
{"Author name", 8, "git log -1 --pretty=format:%an", false, 1},
{"Author email", 8, "git log -1 --pretty=format:%ae", false, 1},
{"Author date", 8, "git log -1 --pretty=format:%ad --date=format:'%d.%m.%Y %H:%M'", false, 1},
{"Branch", 8, "git rev-parse --abbrev-ref HEAD #", true, 1},
{"Revision", 2, "git rev-list --count HEAD #", true, 1},
{"Origin URL", 8, "git remote get-url origin #", true, 1},
{"Push URL", 8, "git remote get-url origin --push #", true, 1},
{"Log", 9, "git log --oneline", false, 1},
{"Untracked", 6, "git ls-files -o", true, -1},
{"Ignored", 6, "git ls-files -i --exclude-standard", true, -1},
{"Modified", 6, "git ls-files -m", true, -1},
{"Untracked "..out, 7, "git ls-files -o", true, -1},
{"Ignored "..out, 7, "git ls-files -i --exclude-standard", true, -1},
{"Modified "..out, 7, "git ls-files -m", true, -1},
}
function ContentGetSupportedField(FieldIndex)
if (fields[FieldIndex + 1] ~= nil ) then
if (fields[FieldIndex + 1][2] == 7) then
return fields[FieldIndex + 1][1], result_true..'|'..result_false, fields[FieldIndex + 1][2];
else
return fields[FieldIndex + 1][1], '', fields[FieldIndex + 1][2];
end
end
return '', '', 0; -- ft_nomorefields
end
function ContentGetDefaultSortOrder(FieldIndex)
return fields[FieldIndex + 1][5];
end
function ContentGetDetectString()
return 'EXT="*"'; -- return detect string
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
local delimpat = SysUtils.PathDelim;
if (delimpat == nil) then
delimpat = "/\\";
end
if (FileName:find("[" .. delimpat .. "]%.%.$")) then
return nil;
end
local attr = SysUtils.FileGetAttr(FileName);
if (attr < 0) or (math.floor(attr / 0x00000004) % 2 ~= 0) then
return nil;
end
local dir = FileName:match("(.*[" .. delimpat .. "])");
if (fields[FieldIndex + 1][3] ~= nil) then
local handle = io.popen('cd "'..dir..'" && '..fields[FieldIndex + 1][3]..' "'..FileName..'"', 'r');
local result = handle:read("*a");
handle:close();
if (result ~= nil) then
if (fields[FieldIndex + 1][4] == true) then
result = result:sub(1, -2);
end
if (fields[FieldIndex + 1][2] == 6) then
if (result ~= '') then
return true;
else
return false;
end
elseif (fields[FieldIndex + 1][2] == 7) then
if (result ~= '') then
return result_true;
else
return result_false;
end
elseif (fields[FieldIndex + 1][2] == 2) then
return tonumber(result);
elseif (fields[FieldIndex + 1][2] == 9) then
if (UnitIndex == 0) then
return result;
else
return nil;
end
else
return result;
end
end
end
return nil; -- invalid
end