Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wezterm = require 'wezterm'
- local act = wezterm.action
- local config = wezterm.config_builder()
- config.enable_scroll_bar = true
- -- config.wrap_early = true -- Active le wrap des lignes longues
- config.set_environment_variables = {
- TERM = "wezterm", -- déjà par défaut, mais utile
- }
- wezterm.on('format-tab-title', function(tab)
- local mux_pane = wezterm.mux.get_pane(tab.active_pane.pane_id)
- if mux_pane then
- local cwd_uri = mux_pane:get_current_working_dir()
- if cwd_uri then
- local host, user, path
- if type(cwd_uri) == 'string' then
- user, host, path = cwd_uri:match('^file://([^@/]*)@?([^/]*)(/.*)$')
- path = path or ''
- else
- host = cwd_uri.host or ''
- user = cwd_uri.username or ''
- path = cwd_uri.file_path or ''
- end
- if path ~= '/' then path = path:gsub('/$', '') end
- host = host or ''
- if host ~= '' and host ~= 'localhost' then
- -- SSH : le titre est déjà correctement formaté par le shell distant
- return tab.active_pane.title
- else
- -- Local : ~/path ou /path
- local home = os.getenv('HOME') or ''
- if home ~= '' and path:sub(1, #home) == home then
- path = '~' .. path:sub(#home + 1)
- end
- if path ~= '' then return path end
- end
- end
- end
- return tab.active_pane.title
- end)
- local function pane_title(p)
- local cwd_uri = p:get_current_working_dir()
- if cwd_uri then
- local host, path
- if type(cwd_uri) == 'string' then
- host, path = cwd_uri:match('^file://([^/]*)(/.*)$')
- host = host or ''
- path = path or ''
- else
- host = cwd_uri.host or ''
- path = cwd_uri.file_path or ''
- end
- if path ~= '/' then path = path:gsub('/$', '') end
- if host ~= '' and host ~= 'localhost' then
- return p:get_title()
- else
- local home = os.getenv('HOME') or ''
- if home ~= '' and path:sub(1, #home) == home then
- path = '~' .. path:sub(#home + 1)
- end
- if path ~= '' then return path end
- end
- end
- return p:get_title()
- end
- wezterm.on('format-window-title', function(tab, pane, tabs)
- local prefix = string.format('[%d/%d] ', tab.tab_index + 1, #tabs)
- local mux_pane = wezterm.mux.get_pane(pane.pane_id)
- if mux_pane then
- return prefix .. pane_title(mux_pane)
- end
- return prefix .. pane.title
- end)
- local function build_choices()
- local choices = {}
- -- active tab par fenêtre (via GUI)
- local active_tab_by_win = {}
- local active_win_title_by_win = {}
- for _, gui_win in ipairs(wezterm.gui.gui_windows()) do
- local tab = gui_win:active_tab()
- if tab then
- local panes = tab:panes()
- active_tab_by_win[gui_win:window_id()] = tab:tab_id()
- active_win_title_by_win[gui_win:window_id()] = #panes > 0 and pane_title(panes[1]) or ''
- end
- end
- -- active pane par tab (via panes_with_info)
- local active_pane_by_tab = {}
- for _, mux_win in ipairs(wezterm.mux.all_windows()) do
- for _, tab in ipairs(mux_win:tabs()) do
- local ok, infos = pcall(function() return tab:panes_with_info() end)
- if ok and infos then
- for _, info in ipairs(infos) do
- if info.is_active then
- active_pane_by_tab[tab:tab_id()] = info.pane:pane_id()
- break
- end
- end
- end
- end
- end
- for _, mux_win in ipairs(wezterm.mux.all_windows()) do
- local win_id = mux_win:window_id()
- local tabs = mux_win:tabs()
- local total = #tabs
- local active_tab_id = active_tab_by_win[win_id]
- local active_title = active_win_title_by_win[win_id] or ''
- local active_index = 1
- for i, tab in ipairs(tabs) do
- if tab:tab_id() == active_tab_id then
- active_index = i
- break
- end
- end
- table.insert(choices, {
- label = string.format('Window #%d: [%d/%d] %s', win_id, active_index, total, active_title),
- id = string.format('w:%d', win_id),
- })
- for _, tab in ipairs(mux_win:tabs()) do
- local tab_id = tab:tab_id()
- local is_active_tab = tab_id == active_tab_id
- local tab_marker = is_active_tab and '>' or ' '
- table.insert(choices, {
- label = string.format(' %s Tab: %s', tab_marker, #tab:panes() > 0 and pane_title(tab:panes()[1]) or tab:get_title()),
- id = string.format('t:%d:%d', win_id, tab_id),
- })
- for _, p in ipairs(tab:panes()) do
- local pane_id = p:pane_id()
- local is_active_pane = pane_id == active_pane_by_tab[tab_id]
- local pane_marker = is_active_pane and '>' or ' '
- local dims = p:get_dimensions()
- local size = dims and string.format('%dx%d', dims.cols or 0, dims.viewport_rows or dims.rows or 0) or '?x?'
- table.insert(choices, {
- label = string.format(' %s Pane #%d [%s]: %s', pane_marker, pane_id, size, pane_title(p)),
- id = string.format('p:%d:%d:%d', win_id, tab_id, pane_id),
- })
- end
- end
- end
- return choices
- end
- local function navigate(id)
- if not id then return end
- local parts = {}
- for part in id:gmatch('[^:]+') do
- table.insert(parts, part)
- end
- local kind = parts[1]
- if kind == 'p' then
- local target_pane_id = tonumber(parts[4])
- for _, w in ipairs(wezterm.mux.all_windows()) do
- for _, t in ipairs(w:tabs()) do
- for _, p in ipairs(t:panes()) do
- if p:pane_id() == target_pane_id then
- t:activate()
- p:activate()
- return
- end
- end
- end
- end
- elseif kind == 't' then
- local target_tab_id = tonumber(parts[3])
- for _, w in ipairs(wezterm.mux.all_windows()) do
- for _, t in ipairs(w:tabs()) do
- if t:tab_id() == target_tab_id then
- t:activate()
- return
- end
- end
- end
- elseif kind == 'w' then
- local target_win_id = tonumber(parts[2])
- for _, w in ipairs(wezterm.mux.all_windows()) do
- if w:window_id() == target_win_id then
- local tabs = w:tabs()
- if #tabs > 0 then
- tabs[1]:activate()
- end
- return
- end
- end
- end
- end
- config.keys = {
- {
- key = 'D',
- mods = 'CTRL|SHIFT',
- action = wezterm.action_callback(function(win, pane)
- pane:move_to_new_window()
- end),
- },
- {
- key = '3',
- mods = 'CTRL|SHIFT|ALT',
- action = act.SplitVertical { domain = 'CurrentPaneDomain' },
- },
- {
- key = 'I',
- mods = 'CTRL|SHIFT',
- action = wezterm.action_callback(function(window, pane)
- local win_id = window:window_id()
- local pane_id = pane:pane_id()
- local tab = window:active_tab()
- local tab_name = tab and (#tab:panes() > 0 and pane_title(tab:panes()[1]) or '') or ''
- local nav_title = string.format('PaneNav from Win %d %s Pane %d', win_id, tab_name, pane_id)
- local choices = build_choices()
- table.insert(choices, 1, { label = nav_title, id = '' })
- window:perform_action(
- act.InputSelector {
- action = wezterm.action_callback(function(_, _, id, _)
- navigate(id)
- end),
- title = nav_title,
- choices = choices,
- fuzzy = true,
- },
- pane
- )
- end),
- },
- }
- return config
Advertisement
Add Comment
Please, Sign In to add comment