81 lines
1.5 KiB
Plaintext
81 lines
1.5 KiB
Plaintext
set_tab(2)
|
|
|
|
function starts(String,Start)
|
|
return string.sub(String,1,string.len(Start))==Start
|
|
end
|
|
|
|
meta_commands["blame"] = function()
|
|
_, y = get_coords()
|
|
handle = io.popen("git blame --porcelain -L"..tostring(math.floor(y)+1)..","..tostring(math.floor(y)+1).." "..get_filename())
|
|
lines = handle:read("*a")
|
|
handle:close()
|
|
|
|
author = string.match(lines, "author (%a+)")
|
|
|
|
if author == nil then
|
|
message("Not checked in!")
|
|
else
|
|
message(author)
|
|
end
|
|
end
|
|
|
|
keys["%"] = function()
|
|
s = get_text()
|
|
count = 0
|
|
|
|
for word in s:gmatch("%w+") do count = count + 1 end
|
|
|
|
message(count .. " words")
|
|
end
|
|
|
|
keys["!"] = function()
|
|
command = prompt("shell command: %s")
|
|
command = string.gsub(command, "%$", get_filename())
|
|
handle = io.popen(command)
|
|
result = handle:read("*a")
|
|
handle:close()
|
|
|
|
result = string.gsub(result, "\n", " ")
|
|
message(result)
|
|
end
|
|
|
|
meta_commands["carp"] = function()
|
|
file = get_filename()
|
|
handle = io.popen("carp --check "..file)
|
|
result = handle:read("*a")
|
|
handle:close()
|
|
|
|
if result.len == 0 then return end
|
|
if starts(result, "Invalid path") then
|
|
message("File not yet saved to disk!")
|
|
return
|
|
end
|
|
|
|
split = result:gmatch(":")
|
|
|
|
if split[0] == file then
|
|
move(tonumber(split[1]), tonumber(split[2]))
|
|
message(table.concat(table.unpack(split, 3), ":"))
|
|
end
|
|
end
|
|
|
|
function get_meta_commands()
|
|
res = ""
|
|
|
|
for k, _ in pairs(meta_commands) do
|
|
res = res .. k .. ", "
|
|
end
|
|
|
|
return res
|
|
end
|
|
|
|
function get_keys()
|
|
res = ""
|
|
|
|
for k, _ in pairs(keys) do
|
|
res = res .. k .. ", "
|
|
end
|
|
|
|
return res
|
|
end
|