Skip to content

Commit 55e907b

Browse files
authored
Merge pull request #279 from mrjones2014/mrj/270/pre-init-mux
feat(mux): Allow mux to be set via `vim.g.smart_splits_multiplexer_integration`
2 parents 621ba58 + 0efe6bf commit 55e907b

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ require('smart-splits').setup({
145145
-- enable or disable a multiplexer integration;
146146
-- automatically determined, unless explicitly disabled or set,
147147
-- by checking the $TERM_PROGRAM environment variable,
148-
-- and the $KITTY_LISTEN_ON environment variable for Kitty
148+
-- and the $KITTY_LISTEN_ON environment variable for Kitty.
149+
-- You can also set this value by setting `vim.g.smart_splits_multiplexer_integration`
150+
-- before the plugin is loaded (e.g. for lazy environments).
149151
multiplexer_integration = nil,
150152
-- disable multiplexer navigation if current multiplexer pane is zoomed
151153
-- this functionality is only supported on tmux and Wezterm due to kitty
@@ -307,6 +309,9 @@ require('smart-splits').start_resize_mode()
307309
`smart-splits.nvim` can also enable seamless navigation between Neovim splits and `tmux`, `wezterm`, or `kitty` panes.
308310
You will need to set up keymaps in your `tmux`, `wezterm`, or `kitty` configs to match the Neovim keymaps.
309311

312+
You can also set the desired multiplexer integration in lazy environments before the plugin is loaded by setting
313+
`vim.g.smart_splits_multiplexer_integration`. The values are the same as described in [Configuration](#configuration).
314+
310315
#### Tmux
311316

312317
Add the following snippet to your `~/.tmux.conf`/`~/.config/tmux/tmux.conf` file (customizing the keys and resize amount if desired):

lua/smart-splits/config.lua

+22-8
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,32 @@ local M = setmetatable({}, {
8080
})
8181

8282
function M.set_default_multiplexer()
83-
-- if explicitly disabled or set to a different value, don't do anything
84-
if config.multiplexer_integration == false and config.multiplexer_integration ~= nil then
85-
return
86-
end
87-
8883
-- if running in a GUI instead of terminal TUI, disable mux
8984
-- because you aren't in any terminal, you're in a Neovim GUI
9085
if mux_utils.are_we_gui() then
86+
log.debug('Disabling multiplexer_integration because nvim is running in a GUI, not a TTY')
9187
config.multiplexer_integration = false
92-
return nil
88+
return
89+
end
90+
91+
-- for lazy environments, allow users to specify the mux before the plugin
92+
-- is loaded by using a `vim.g` variable
93+
if vim.g.smart_splits_multiplexer_integration ~= nil then
94+
log.debug(
95+
'Taking multiplexer_integration from vim.g.multiplexer_integration: %s',
96+
vim.g.smart_splits_multiplexer_integration
97+
)
98+
config.multiplexer_integration = vim.g.smart_splits_multiplexer_integration
99+
-- if set to 0 or 1, convert to boolean
100+
if type(config.multiplexer_integration) == 'number' then
101+
config.multiplexer_integration = config.multiplexer_integration ~= 0
102+
end
103+
return
104+
end
105+
106+
-- if explicitly disabled or set to a different value, don't do anything
107+
if config.multiplexer_integration == false and config.multiplexer_integration ~= nil then
108+
return
93109
end
94110

95111
local term = vim.trim((vim.env.TERM_PROGRAM or ''):lower())
@@ -107,8 +123,6 @@ function M.set_default_multiplexer()
107123
else
108124
log.debug('Auto-detected multiplexer back-end: none')
109125
end
110-
111-
return type(config.multiplexer_integration) == 'string' and config.multiplexer_integration or nil
112126
end
113127

114128
function M.setup(new_config)

0 commit comments

Comments
 (0)