diff --git a/README.md b/README.md index 44085f6..c7f471b 100644 --- a/README.md +++ b/README.md @@ -38,37 +38,37 @@ Add this to your `keymap.toml`: ```toml [[manager.prepend_keymap]] on = [ "P", "s" ] -run = "plugin projects --args=save" +run = "plugin projects save" desc = "Save current project" [[manager.prepend_keymap]] on = [ "P", "l" ] -run = "plugin projects --args=load" +run = "plugin projects load" desc = "Load project" [[manager.prepend_keymap]] on = [ "P", "P" ] -run = "plugin projects --args=load_last" +run = "plugin projects load_last" desc = "Load last project" [[manager.prepend_keymap]] on = [ "P", "d" ] -run = "plugin projects --args=delete" +run = "plugin projects delete" desc = "Delete project" [[manager.prepend_keymap]] on = [ "P", "D" ] -run = "plugin projects --args=delete_all" +run = "plugin projects delete_all" desc = "Delete all projects" [[manager.prepend_keymap]] on = [ "P", "m" ] -run = "plugin projects --args='merge current'" +run = "plugin projects 'merge current'" desc = "Merge current tab to other projects" [[manager.prepend_keymap]] on = [ "P", "M" ] -run = "plugin projects --args='merge all'" +run = "plugin projects 'merge all'" desc = "Merge current project to other projects" ``` @@ -77,7 +77,7 @@ If you want to save the last project when exiting, map the default `quit` key to ```toml [[manager.prepend_keymap]] on = [ "q" ] -run = "plugin projects --args=quit" +run = "plugin projects quit" desc = "Save last project and exit the process" ``` diff --git a/init.lua b/main.lua similarity index 93% rename from init.lua rename to main.lua index e902afe..73cea2b 100644 --- a/init.lua +++ b/main.lua @@ -514,17 +514,17 @@ local SUPPORTED_KEYS = { { on = "z" }, } -local _load_config = ya.sync(function(state, args) +local _load_config = ya.sync(function(state, opts) state.save = { method = "yazi", lua_save_path = "", } - if type(args.save) == "table" then - if type(args.save.method) == "string" then - state.save.method = args.save.method + if type(opts.save) == "table" then + if type(opts.save.method) == "string" then + state.save.method = opts.save.method end - if type(args.save.lua_save_path) == "string" then - state.save.lua_save_path = args.save.lua_save_path + if type(opts.save.lua_save_path) == "string" then + state.save.lua_save_path = opts.save.lua_save_path else local lua_save_path local appdata = os.getenv("APPDATA") @@ -543,24 +543,24 @@ local _load_config = ya.sync(function(state, args) update_after_load = true, load_after_start = false, } - if type(args.last) == "table" then - if type(args.last.update_after_save) == "boolean" then - state.last.update_after_save = args.last.update_after_save + if type(opts.last) == "table" then + if type(opts.last.update_after_save) == "boolean" then + state.last.update_after_save = opts.last.update_after_save end - if type(args.last.update_after_load) == "boolean" then - state.last.update_after_load = args.last.update_after_load + if type(opts.last.update_after_load) == "boolean" then + state.last.update_after_load = opts.last.update_after_load end - if type(args.last.load_after_start) == "boolean" then - state.last.load_after_start = args.last.load_after_start + if type(opts.last.load_after_start) == "boolean" then + state.last.load_after_start = opts.last.load_after_start end end state.merge = { quit_after_merge = false, } - if type(args.merge) == "table" then - if type(args.merge.quit_after_merge) == "boolean" then - state.merge.quit_after_merge = args.merge.quit_after_merge + if type(opts.merge) == "table" then + if type(opts.merge.quit_after_merge) == "boolean" then + state.merge.quit_after_merge = opts.merge.quit_after_merge end end @@ -570,18 +570,18 @@ local _load_config = ya.sync(function(state, args) timeout = 3, level = "info", } - if type(args.notify) == "table" then - if type(args.notify.enable) == "boolean" then - state.notify.enable = args.notify.enable + if type(opts.notify) == "table" then + if type(opts.notify.enable) == "boolean" then + state.notify.enable = opts.notify.enable end - if type(args.notify.title) == "string" then - state.notify.title = args.notify.title + if type(opts.notify.title) == "string" then + state.notify.title = opts.notify.title end - if type(args.notify.timeout) == "number" then - state.notify.timeout = args.notify.timeout + if type(opts.notify.timeout) == "number" then + state.notify.timeout = opts.notify.timeout end - if type(args.notify.level) == "string" then - state.notify.level = args.notify.level + if type(opts.notify.level) == "string" then + state.notify.level = opts.notify.level end end end) @@ -821,6 +821,11 @@ local _merge_event = ya.sync(function(state) end) return { + setup = function(_, opts) + _load_config(opts) + _load_projects() + _merge_event() + end, entry = function(_, job) local action = job.args[1] if not action then @@ -909,9 +914,4 @@ return { delete_project(selected_idx) end end, - setup = function(_, args) - _load_config(args) - _load_projects() - _merge_event() - end, }