tmux.nvim icon indicating copy to clipboard operation
tmux.nvim copied to clipboard

[FR] Omit setup step if use default settings

Open bangedorrunt opened this issue 3 years ago • 3 comments

Some plugins allow us to omit setup call if we use default setting. Please only force user to setup call if they wanna change default behavior. This will help remove boilerplate code in our config. Thank you

bangedorrunt avatar Sep 12 '22 21:09 bangedorrunt

heho,

ty for the idea. need some time to get this done. if you want it now, please file a pr :)

regards Alexander

aserowy avatar Sep 14 '22 07:09 aserowy

heho,

ty for the idea. need some time to get this done. if you want it now, please file a pr :)

regards Alexander

@aserowy

I wanna give it a go, but I'm new to Lua so please help me out. Here is my current implementation. However it doesn't work as expected.

If I called require('tmux').setup {} it results in error

Screen Shot 2022-09-14 at 8 19 00 pm
diff --git a/lua/tmux/init.lua b/lua/tmux/init.lua
index c40dc66..afab83a 100644
--- a/lua/tmux/init.lua
+++ b/lua/tmux/init.lua
@@ -5,6 +5,20 @@ local navigation = require("tmux.navigation")
 local resize = require("tmux.resize")
 local tmux = require("tmux.wrapper.tmux")
 
+local options = {
+    copy_sync = {
+        enable = true,
+    },
+    navigation = {
+        enable_default_keybindings = true,
+    },
+    resize = {
+        enable_default_keybindings = true,
+    },
+}
+
+local logging = {}
+
 local M = {
     move_left = navigation.to_left,
     move_bottom = navigation.to_bottom,
@@ -20,23 +34,31 @@ local M = {
     resize_right = resize.to_right,
 }
 
-function M.setup(options, logging)
-    log.setup()
+log.setup()
 
-    log.debug("setup tmux wrapper")
-    tmux.setup()
+log.debug("setup tmux wrapper")
+tmux.setup()
 
-    log.debug("setup config")
-    config.setup(options, logging)
+log.debug("setup config")
 
-    log.debug("setup copy")
-    copy.setup()
+function M.setup(options_, logging_)
+    if options_ == nil or options_ == "" then
+        return
+    end
+    for k, v in pairs(options_) do
+        options[k] = v
+    end
+    logging = logging_ or {}
+end
 
-    log.debug("setup navigate")
-    navigation.setup()
+config.setup(options, {})
 
-    log.debug("setup resize")
-    resize.setup()
-end
+log.debug("setup copy")
+copy.setup()
+
+log.debug("setup navigate")
+navigation.setup()
 
+log.debug("setup resize")
+resize.setup()
return M

bangedorrunt avatar Sep 14 '22 09:09 bangedorrunt

I made a PR, please have a look

bangedorrunt avatar Sep 14 '22 11:09 bangedorrunt

Merged it finally 🙃

aserowy avatar Sep 20 '22 10:09 aserowy

Thank you!

bangedorrunt avatar Sep 21 '22 07:09 bangedorrunt