diff options
author | rxi <rxi@users.noreply.github.com> | 2020-05-24 14:03:44 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-05-24 14:03:44 +0100 |
commit | 5dd2f7cda584d43b40af0db69e41312f98c71611 (patch) | |
tree | d267642590964a613ad3bea7238f0215e71b3b5b /plugins | |
parent | 9e2cf49be6973dbf6df380b43ccb929fb92761b0 (diff) | |
download | lite-xl-plugins-5dd2f7cda584d43b40af0db69e41312f98c71611.tar.gz lite-xl-plugins-5dd2f7cda584d43b40af0db69e41312f98c71611.zip |
Updates for v1.05
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/gitstatus.lua | 27 | ||||
-rw-r--r-- | plugins/workspace.lua | 21 |
2 files changed, 21 insertions, 27 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 diff --git a/plugins/workspace.lua b/plugins/workspace.lua index 03304a9..bb5e0d4 100644 --- a/plugins/workspace.lua +++ b/plugins/workspace.lua @@ -1,7 +1,7 @@ local core = require "core" local DocView = require "core.docview" -local workspace_filename = core.project_dir .. "/.lite_workspace.lua" +local workspace_filename = ".lite_workspace.lua" local function serialize(val) @@ -36,24 +36,9 @@ local function get_unlocked_root(node) end -local function save_path(filename) - local proj = system.absolute_path(core.project_dir) - filename = system.absolute_path(filename) - if filename:sub(1, #proj) == proj then - return "." .. filename:sub(#proj + 1) - end - return filename -end - - -local function load_path(filename) - return filename:gsub("^%.", core.project_dir) -end - - local function save_docview(dv) return { - filename = save_path(dv.doc.filename), + filename = dv.doc.filename, selection = { dv.doc:get_selection() }, scroll = { x = dv.scroll.to.x, y = dv.scroll.to.y } } @@ -61,7 +46,7 @@ end local function load_docview(t) - local ok, doc = pcall(core.open_doc, load_path(t.filename)) + local ok, doc = pcall(core.open_doc, t.filename) if not ok then return DocView(core.open_doc()) end |