mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-12 01:50:27 +09:00
Add diff gutter
This commit is contained in:
20
runtime/plugins/diff/diff.lua
Normal file
20
runtime/plugins/diff/diff.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
VERSION = "1.0.0"
|
||||
|
||||
local os = import("os")
|
||||
local filepath = import("path/filepath")
|
||||
local shell = import("micro/shell")
|
||||
|
||||
function onBufferOpen(buf)
|
||||
if (not buf.Type.Scratch) and (buf.Path ~= "") then
|
||||
-- check that file exists
|
||||
local _, err = os.Stat(buf.AbsPath)
|
||||
if err == nil then
|
||||
local dirName, fileName = filepath.Split(buf.AbsPath)
|
||||
local diffBase, err = shell.ExecCommand("git", "-C", dirName, "show", "HEAD:./" .. fileName)
|
||||
if err ~= nil then
|
||||
diffBase = buf:Bytes()
|
||||
end
|
||||
buf:SetDiffBase(diffBase)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user