aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--manifest.json9
-rw-r--r--plugins/gitopen.lua53
3 files changed, 62 insertions, 1 deletions
diff --git a/README.md b/README.md
index 03039da..2a55903 100644
--- a/README.md
+++ b/README.md
@@ -77,6 +77,7 @@ but only with a `url` must provide a `checksum` that matches the existing plugin
| [`ghmarkdown`](plugins/ghmarkdown.lua?raw=1) | Opens a preview of the current markdown file in a browser window *([screenshot](https://user-images.githubusercontent.com/3920290/82754898-f7394600-9dc7-11ea-8278-2305363ed372.png))* |
| [`gitblame`](https://github.com/juliardi/lite-xl-gitblame)\* | Shows "git blame" information of a line *([screenshot](https://raw.githubusercontent.com/juliardi/lite-xl-gitblame/main/screenshot_1.png))* |
| [`gitdiff_highlight`](https://github.com/vincens2005/lite-xl-gitdiff-highlight)\* | highlight changed lines from git *([screenshot](https://raw.githubusercontent.com/vincens2005/lite-xl-gitdiff-highlight/master/screenshot.png))* |
+| [`gitopen`](plugins/gitopen.lua?raw=1) | Open project files that are in a git commit (default=HEAD) |
| [`gitstatus`](plugins/gitstatus.lua?raw=1) | Displays git branch and insert/delete count in status bar *([screenshot](https://user-images.githubusercontent.com/3920290/81107223-bcea3080-8f0e-11ea-8fc7-d03173f42e33.png))* |
| [`gofmt`](plugins/gofmt.lua?raw=1) | Auto-formats the current go file, adds the missing imports and the missing return cases |
| [`immersive-title`](https://github.com/takase1121/lite-xl-immersive-title)\* | Dark (or even Mica!) title bar for Lite XL |
diff --git a/manifest.json b/manifest.json
index a2ffccf..ed3cb30 100644
--- a/manifest.json
+++ b/manifest.json
@@ -36,7 +36,7 @@
"mod_version": "3"
},
{
- "description": "Shows the current time and date in a view with large text *([screenshot](https://user-images.githubusercontent.com/3920290/82752891-3318df00-9db9-11ea-803f-261d80d5cf53.png))*",
+ "description": "Shows the current time and date in a view with large text *([screenshot](https://user-images.git hubusercontent.com/3920290/82752891-3318df00-9db9-11ea-803f-261d80d5cf53.png))*",
"version": "0.1",
"path": "plugins/bigclock.lua",
"id": "bigclock",
@@ -280,6 +280,13 @@
"id": "gitdiff_highlight"
},
{
+ "description": "Open project files that are in a git commit (default=HEAD)",
+ "version": "0.1",
+ "path": "plugins/gitopen.lua",
+ "id": "gitopen",
+ "mod_version": "3"
+ },
+ {
"description": "Displays git branch and insert/delete count in status bar *([screenshot](https://user-images.githubusercontent.com/3920290/81107223-bcea3080-8f0e-11ea-8fc7-d03173f42e33.png))*",
"version": "0.1",
"path": "plugins/gitstatus.lua",
diff --git a/plugins/gitopen.lua b/plugins/gitopen.lua
new file mode 100644
index 0000000..4870191
--- /dev/null
+++ b/plugins/gitopen.lua
@@ -0,0 +1,53 @@
+-- mod-version:3
+local core = require "core"
+local command = require "core.command"
+local common = require "core.common"
+
+
+local function exec(cmd)
+ local proc = process.start(cmd)
+ while proc:running() do
+ coroutine.yield(0.1)
+ end
+ if proc:returncode() > 0 then
+ core.error("ERROR - command: " .. table.concat(cmd, " "))
+ end
+ return proc:read_stdout() or ""
+end
+
+
+local function git_find_files_and_open(commit)
+ local git_root = exec({"git", "rev-parse", "--show-toplevel"}):match( "^%s*(.-)%s*$" )
+ local file_list_str = exec({"git", "show", "--name-only", "--pretty=format:", commit})
+
+ local git_files = {}
+ for str in string.gmatch(file_list_str, "([^\n]+)") do
+ git_files[git_root .. PATHSEP .. str] = true
+ end
+
+ for dir, item in core.get_project_files() do
+ local key = dir .. PATHSEP .. item.filename
+ if git_files[key] then
+ core.root_view:open_doc(core.open_doc(item.filename))
+ end
+ end
+end
+
+-- works in any context
+command.add(nil, {
+ ["gitopen:open-from-commit"] = function(dv)
+ core.command_view:enter("Which commit? (default=HEAD)", {
+ submit = function(commit)
+ if commit == nil or commit == "" then
+ commit = "HEAD"
+ end
+ -- open the files in the background, return immediately
+ core.add_thread(
+ function ()
+ git_find_files_and_open(commit)
+ end
+ )
+ end
+ })
+ end,
+})