File: status.lua

package info (click to toggle)
micro 2.0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,448 kB
  • sloc: sh: 232; makefile: 72; xml: 24
file content (66 lines) | stat: -rw-r--r-- 1,581 bytes parent folder | download | duplicates (3)
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
VERSION = "1.0.0"

local micro = import("micro")
local buffer = import("micro/buffer")
local config = import("micro/config")
local humanize = import("humanize")

function init()
    micro.SetStatusInfoFn("status.branch")
    micro.SetStatusInfoFn("status.hash")
    micro.SetStatusInfoFn("status.paste")
    micro.SetStatusInfoFn("status.vcol")
    micro.SetStatusInfoFn("status.lines")
    micro.SetStatusInfoFn("status.bytes")
    micro.SetStatusInfoFn("status.size")
    config.AddRuntimeFile("status", config.RTHelp, "help/status.md")
end

function lines(b)
    return tostring(b:LinesNum())
end

function vcol(b)
    return tostring(b:GetActiveCursor():GetVisualX())
end

function bytes(b)
    return tostring(b:Size())
end

function size(b)
    return humanize.Bytes(b:Size())
end

function branch(b)
    if b.Type.Kind ~= buffer.BTInfo then
        local shell = import("micro/shell")
        local strings = import("strings")

        local branch, err = shell.ExecCommand("git", "rev-parse", "--abbrev-ref", "HEAD")
        if err == nil then
            return strings.TrimSpace(branch)
        end
        return ""
    end
end

function hash(b)
    if b.Type.Kind ~= 5 then
        local shell = import("micro/shell")
        local strings = import("strings")

        local hash, err = shell.ExecCommand("git", "rev-parse", "--short", "HEAD")
        if err == nil then
            return strings.TrimSpace(hash)
        end
        return ""
    end
end

function paste(b)
    if config.GetGlobalOption("paste") then
        return "PASTE "
    end
    return ""
end