update wezterm format-tab-title event handler

add support for using wezterm's normal/suggested tab title for
certain processes
This commit is contained in:
Gered 2024-09-14 23:49:14 -04:00
parent 3e61dbfa2c
commit dfe1d530b5

View file

@ -13,6 +13,7 @@ config.hide_tab_bar_if_only_one_tab = true
config.tab_bar_at_bottom = true
config.use_fancy_tab_bar = false
config.show_new_tab_button_in_tab_bar = false
config.tab_max_width = 32
config.enable_scroll_bar = true
config.window_background_opacity = 0.8
config.window_padding = {
@ -99,6 +100,18 @@ local process_icons = {
["wget"] = wezterm.nerdfonts.mdi_arrow_down_box,
}
local process_use_suggested_title = {
["ssh"] = true,
}
local function get_suggested_tab_title(tab_info)
local title = tab_info.tab_title
if title and #title > 0 then
return title
end
return tab_info.active_pane.title
end
local function get_current_working_dir(tab)
local current_dir = tab.active_pane and tab.active_pane.current_working_dir or { file_path = "" }
local HOME_DIR = os.getenv("HOME")
@ -116,7 +129,10 @@ local function get_process(tab)
process_name = "kubectl"
end
return process_icons[process_name] or string.format("[%s]", process_name)
return {
Icon = process_icons[process_name] or string.format("[%s]", process_name),
Process = process_name,
}
end
local SOLID_LEFT_ARROW = wezterm.nerdfonts.pl_right_hard_divider
@ -138,7 +154,17 @@ wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_wid
})
local process = get_process(tab)
local title = process and string.format(" %s (%s) ", process, cwd) or " [?] "
local title
if process then
local sub_title = cwd
if process_use_suggested_title[process.Process] then
sub_title = get_suggested_tab_title(tab)
end
local icon = process.Icon or string.format("[%s]", process.Process)
title = string.format(" %s (%s) ", icon, sub_title)
end
if has_unseen_output then
return {