| 1 |
VERSION = "1.0.0" |
| 2 |
|
| 3 |
local micro = import("micro") |
| 4 |
local buffer = import("micro/buffer") |
| 5 |
local config = import("micro/config") |
| 6 |
local shell = import("micro/shell") |
| 7 |
local filepath = import("filepath") |
| 8 |
local humanize = import("humanize") |
| 9 |
local strings = import("strings") |
| 10 |
|
| 11 |
function init() |
| 12 |
micro.SetStatusInfoFn("status.branch") |
| 13 |
micro.SetStatusInfoFn("status.hash") |
| 14 |
micro.SetStatusInfoFn("status.paste") |
| 15 |
micro.SetStatusInfoFn("status.vcol") |
| 16 |
micro.SetStatusInfoFn("status.lines") |
| 17 |
micro.SetStatusInfoFn("status.bytes") |
| 18 |
micro.SetStatusInfoFn("status.size") |
| 19 |
config.AddRuntimeFile("status", config.RTHelp, "help/status.md") |
| 20 |
end |
| 21 |
|
| 22 |
function lines(b) |
| 23 |
return tostring(b:LinesNum()) |
| 24 |
end |
| 25 |
|
| 26 |
function vcol(b) |
| 27 |
return tostring(b:GetActiveCursor():GetVisualX(false)) |
| 28 |
end |
| 29 |
|
| 30 |
function bytes(b) |
| 31 |
return tostring(b:Size()) |
| 32 |
end |
| 33 |
|
| 34 |
function size(b) |
| 35 |
return humanize.Bytes(b:Size()) |
| 36 |
end |
| 37 |
|
| 38 |
local function parseRevision(b, opt) |
| 39 |
if b.Type.Kind ~= buffer.BTInfo then |
| 40 |
local dir = filepath.Dir(b.Path) |
| 41 |
local str, err = shell.ExecCommand("git", "-C", dir, "rev-parse", opt, "HEAD") |
| 42 |
if err == nil then |
| 43 |
return strings.TrimSpace(str) |
| 44 |
end |
| 45 |
end |
| 46 |
return "" |
| 47 |
end |
| 48 |
|
| 49 |
function branch(b) |
| 50 |
return parseRevision(b, "--abbrev-ref") |
| 51 |
end |
| 52 |
|
| 53 |
function hash(b) |
| 54 |
return parseRevision(b, "--short") |
| 55 |
end |
| 56 |
|
| 57 |
function paste(b) |
| 58 |
if config.GetGlobalOption("paste") then |
| 59 |
return "PASTE " |
| 60 |
end |
| 61 |
return "" |
| 62 |
end |