-
Notifications
You must be signed in to change notification settings - Fork 24
/
lslockswdx.lua
62 lines (51 loc) · 1.55 KB
/
lslockswdx.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
local filename = '';
local fields = {
{"COMMAND", 8},
{"PID", 2},
{"TYPE", 8},
{"BLOCKER", 8},
{"MODE", 8},
{"M", 2},
{"START", 2},
{"END", 2},
}
function ContentGetSupportedField(FieldIndex)
if (fields[FieldIndex + 1] ~= nil ) then
return fields[FieldIndex + 1][1], '', fields[FieldIndex + 1][2];
end
return '', '', 0; -- ft_nomorefields
end
local function escape_str(str)
local magic_chars = {"%", ".", "-", "+", "*", "?", "^", "$", "(", ")", "["};
for i, chr in pairs(magic_chars) do
str = str:gsub("%" .. chr, "%%%" .. chr);
end
return str;
end
function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if (filename ~= FileName) then
local handle = io.popen('lslocks -u -o COMMAND,PID,TYPE,BLOCKER,MODE,M,START,END,PATH', 'r');
local output = handle:read("*a");
handle:close();
filename = FileName;
if (output ~= nil) then
local pattern = '\n(%w+)%s+(%d+)%s+(%u+)%s+(%w*)%s+(%u+)%s+(%d+)%s+(%d+)%s+(%d+) ' .. escape_str(FileName) .. '\n';
fields[1][3],
fields[2][3],
fields[3][3],
fields[4][3],
fields[5][3],
fields[6][3],
fields[7][3],
fields[8][3] = output:match(pattern);
else
for i = 1, #fields do
fields[i][3] = nil;
end
end
end
if (fields[FieldIndex + 1] ~= nil) then
return fields[FieldIndex + 1][3];
end
return nil; -- invalid
end