From 84b2584ff24d925346692a76a1bfb4b14fd2d0ce Mon Sep 17 00:00:00 2001 From: jgmdev Date: Thu, 27 Aug 2020 20:39:55 -0400 Subject: [PATCH 1/2] Added homeuserdata --- README.md | 1 + plugins/homeuserdata.lua | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 plugins/homeuserdata.lua diff --git a/README.md b/README.md index 9ef3b739..a7215a6b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Plugin | Description [`gofmt`](plugins/gofmt.lua?raw=1) | Auto-formats the current go file, adds the missing imports and the missing return cases [`hidelinenumbers`](plugins/hidelinenumbers.lua?raw=1) | Hides the line numbers on the left of documents *([screenshot](https://user-images.githubusercontent.com/3920290/81692043-b8b19c00-9455-11ea-8d74-ad99be4b9c5f.png))* [`hidestatus`](plugins/hidestatus.lua?raw=1) | Hides the status bar at the bottom of the window +[`homeuserdata`](plugins/homeuserdata.lua?raw=1) | Loads init.lua from ~/.config/lite or ~/.lite, allowing you to save plugins or color themes on these directories and adds the 'Open Home User Module' command. [`inanimate`](plugins/inanimate.lua?raw=1) | Disables all transition animations [`indentguide`](plugins/indentguide.lua?raw=1) | Adds indent guides *([screenshot](https://user-images.githubusercontent.com/3920290/79640716-f9860000-818a-11ea-9c3b-26d10dd0e0c0.png))* [`language_angelscript`](plugins/language_angelscript.lua?raw=1) | Syntax for the [Angelscript](https://www.angelcode.com/angelscript/) programming language diff --git a/plugins/homeuserdata.lua b/plugins/homeuserdata.lua new file mode 100644 index 00000000..1adc7093 --- /dev/null +++ b/plugins/homeuserdata.lua @@ -0,0 +1,76 @@ +local core = require "core" +local command = require "core.command" +local CommandView = require "core.commandview" + +-- don't execute plugin on windows +if package.cpath:match("%p[\\|/]?%p(%a+)") == "dll" then + return +end + +-- check if home directory is set +local home_dir = os.getenv("HOME") + +if not home_dir then + return +end + +-- user configurations path in order of preference +local configs = { + home_dir .. "/.config/lite", + home_dir .. "/.lite" +} + +-- load user settings +for i,dir in ipairs(configs) do + local redirect = " 2>/dev/null" + if system.get_file_info(dir) then + package.path = package.path .. ";" .. dir .. "/?/init.lua" + package.path = package.path .. ";" .. dir .. "/?.lua" + + if system.get_file_info(dir .. "/init.lua") then + local init = loadfile(dir .. "/init.lua") + init() + end + + break + end +end + +command.add(nil, { + ["core:open-home-user-module"] = function() + local directory = nil + for i,dir in ipairs(configs) do + local redirect = " 2>/dev/null" + if system.get_file_info(dir) then + directory = dir + end + end + if not directory then + directory = home_dir .. "/.config/lite" + os.execute("mkdir -p " .. directory) + end + + local filename = directory .. "/init.lua" + + if system.get_file_info(filename) then + core.root_view:open_doc(core.open_doc(filename)) + else + local doc = core.open_doc() + core.root_view:open_doc(doc) + + local content = "-- put user settings here\n\n" + .. "local keymap = require \"core.keymap\"\n" + .. "local config = require \"core.config\"\n" + .. "local style = require \"core.style\"\n\n" + .. "-- load plugins from " .. directory .. "/plugins:\n" + .. "-- require \"plugins.myplugin\"\n\n" + .. "-- load themes from " .. directory .. "/colors:\n" + .. "-- require \"colors.mytheme\"\n\n" + .. "-- key binding:\n" + .. "-- keymap.add { [\"ctrl+escape\"] = \"core:quit\" }\n" + + doc:insert(1, 1, content) + doc:save(filename) + end + end, +}) From 930a19959aecaf6771e9d76a830ec30134a36193 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Fri, 28 Aug 2020 13:24:44 -0400 Subject: [PATCH 2/2] [homeuserdata] removed left over unused variable. --- plugins/homeuserdata.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/homeuserdata.lua b/plugins/homeuserdata.lua index 1adc7093..31700aaf 100644 --- a/plugins/homeuserdata.lua +++ b/plugins/homeuserdata.lua @@ -22,7 +22,6 @@ local configs = { -- load user settings for i,dir in ipairs(configs) do - local redirect = " 2>/dev/null" if system.get_file_info(dir) then package.path = package.path .. ";" .. dir .. "/?/init.lua" package.path = package.path .. ";" .. dir .. "/?.lua" @@ -40,7 +39,6 @@ command.add(nil, { ["core:open-home-user-module"] = function() local directory = nil for i,dir in ipairs(configs) do - local redirect = " 2>/dev/null" if system.get_file_info(dir) then directory = dir end