aboutsummaryrefslogtreecommitdiff
path: root/plugins/gitstatus.lua
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2020-05-24 14:03:44 +0100
committerrxi <rxi@users.noreply.github.com>2020-05-24 14:03:44 +0100
commit5dd2f7cda584d43b40af0db69e41312f98c71611 (patch)
treed267642590964a613ad3bea7238f0215e71b3b5b /plugins/gitstatus.lua
parent9e2cf49be6973dbf6df380b43ccb929fb92761b0 (diff)
downloadlite-xl-plugins-5dd2f7cda584d43b40af0db69e41312f98c71611.tar.gz
lite-xl-plugins-5dd2f7cda584d43b40af0db69e41312f98c71611.zip
Updates for v1.05
Diffstat (limited to 'plugins/gitstatus.lua')
-rw-r--r--plugins/gitstatus.lua27
1 files changed, 18 insertions, 9 deletions
diff --git a/plugins/gitstatus.lua b/plugins/gitstatus.lua
index 4fe043f..a9db50b 100644
--- a/plugins/gitstatus.lua
+++ b/plugins/gitstatus.lua
@@ -10,21 +10,30 @@ local git = {
deletes = 0,
}
+
+local tempfile = ".lite_gitstatus_" .. os.tmpname():gsub("%W", "")
+
+local function exec(cmd, wait)
+ system.exec(cmd .. " >" .. tempfile)
+ coroutine.yield(wait)
+ local fp = io.open(tempfile)
+ local res = fp:read("*a")
+ fp:close()
+ os.remove(tempfile)
+ return res
+end
+
+
core.add_thread(function()
while true do
if system.get_file_info(".git") then
-- get branch name
- local fp = io.popen("git rev-parse --abbrev-ref HEAD")
- git.branch = fp:read("*l")
- fp:close()
+ git.branch = exec("git rev-parse --abbrev-ref HEAD", 1):match("[^\n]*")
-- get diff
- local fp = io.popen("git diff --stat")
- local last_line = ""
- for line in fp:lines() do last_line = line end
- fp:close()
- git.inserts = tonumber(last_line:match("(%d+) ins")) or 0
- git.deletes = tonumber(last_line:match("(%d+) del")) or 0
+ local line = exec("git diff --stat", 1):match("[^\n]*%s*$")
+ git.inserts = tonumber(line:match("(%d+) ins")) or 0
+ git.deletes = tonumber(line:match("(%d+) del")) or 0
else
git.branch = nil