From f91641509d95d0904c77c9dd62f024c040332043 Mon Sep 17 00:00:00 2001 From: Dmitry Fisenko Date: Fri, 22 Mar 2024 20:53:03 -0400 Subject: [PATCH] chore: update right side --- config/wezterm/cfg_appearance.lua | 30 +++++++++++++++++-- config/wezterm/cfg_keys.lua | 15 ++++++++++ config/wezterm/lib/helpers.lua | 49 +++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 config/wezterm/lib/helpers.lua diff --git a/config/wezterm/cfg_appearance.lua b/config/wezterm/cfg_appearance.lua index 267071b..de23afc 100644 --- a/config/wezterm/cfg_appearance.lua +++ b/config/wezterm/cfg_appearance.lua @@ -1,4 +1,5 @@ local wezterm = require("wezterm") +local helpers = require("lib.helpers") local M = {} @@ -8,8 +9,9 @@ function M.setup(cfg) cfg.enable_tab_bar = true cfg.use_fancy_tab_bar = false cfg.tab_bar_at_bottom = false - cfg.tab_max_width = 24 + cfg.tab_max_width = 30 cfg.hide_tab_bar_if_only_one_tab = true + cfg.status_update_interval = 100 cfg.font_size = 16.0 cfg.font = wezterm.font({ @@ -25,8 +27,8 @@ function M.setup(cfg) cfg.window_background_opacity = 0.95 cfg.window_decorations = "RESIZE" cfg.window_padding = { - left = 0, - right = 0, + left = 5, + right = 5, top = 0, bottom = 0, } @@ -37,6 +39,28 @@ function M.setup(cfg) cfg.initial_rows = 50 cfg.initial_cols = 180 + + wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width) + local position = tab.tab_index + 1 + local process_icon = helpers.get_process(tab) + -- ensure that the titles fit in the available space + local tab_text = wezterm.truncate_right(helpers.tab_title(tab), max_width - 2) + local tab_title = string.format(" ⌘%d %s %s ", position, process_icon, tab_text) + + return { + { Text = tab_title }, + } + end) + + wezterm.on("update-right-status", function(window, pane) + local date = wezterm.strftime("%a %b %-d %H:%M") + + window:set_right_status(wezterm.format({ + { Text = wezterm.nerdfonts.md_calendar_clock .. " " .. date }, + { Text = " | " }, + { Text = wezterm.nerdfonts.oct_person .. " " .. wezterm.hostname() }, + })) + end) end return M diff --git a/config/wezterm/cfg_keys.lua b/config/wezterm/cfg_keys.lua index cce1e95..b7c0728 100644 --- a/config/wezterm/cfg_keys.lua +++ b/config/wezterm/cfg_keys.lua @@ -45,6 +45,21 @@ function M.setup(cfg) { key = "LeftArrow", mods = "CMD", action = act.SendString("\x01") }, { key = "RightArrow", mods = "CMD", action = act.SendString("\x05") }, { key = "Backspace", mods = "CMD", action = act.SendString("\x15") }, + { + key = "E", + mods = "CTRL|SHIFT", + action = act.PromptInputLine({ + description = "Enter new name for tab", + action = wezterm.action_callback(function(window, pane, line) + -- line will be `nil` if they hit escape without entering anything + -- An empty string if they just hit enter + -- Or the actual line of text they wrote + if line then + window:active_tab():set_title(line) + end + end), + }), + }, } cfg.key_tables = { diff --git a/config/wezterm/lib/helpers.lua b/config/wezterm/lib/helpers.lua new file mode 100644 index 0000000..5e3db7d --- /dev/null +++ b/config/wezterm/lib/helpers.lua @@ -0,0 +1,49 @@ +local wezterm = require("wezterm") + +local M = {} + +local process_icons = { + ["docker"] = wezterm.nerdfonts.linux_docker, + ["docker-compose"] = wezterm.nerdfonts.linux_docker, + ["psql"] = wezterm.nerdfonts.dev_postgresql, + ["nvim"] = wezterm.nerdfonts.custom_vim, + ["make"] = wezterm.nerdfonts.seti_makefile, + ["vim"] = wezterm.nerdfonts.dev_vim, + ["zsh"] = wezterm.nerdfonts.dev_terminal, + ["bash"] = wezterm.nerdfonts.cod_terminal_bash, + ["htop"] = wezterm.nerdfonts.mdi_chart_donut_variant, + ["cargo"] = wezterm.nerdfonts.dev_rust, + ["sudo"] = wezterm.nerdfonts.fa_hashtag, + ["git"] = wezterm.nerdfonts.dev_git, + ["lua"] = wezterm.nerdfonts.seti_lua, + ["wget"] = wezterm.nerdfonts.mdi_arrow_down_box, + ["curl"] = wezterm.nerdfonts.mdi_flattr, + ["gh"] = wezterm.nerdfonts.dev_github_badge, + ["ruby"] = wezterm.nerdfonts.cod_ruby, + ["node"] = wezterm.nerdfonts.dev_nodejs_small, + ["tmux"] = wezterm.nerdfonts.cod_terminal_tmux, +} + +function M.get_process(tab) + local process_name = tab.active_pane.foreground_process_name:match("([^/\\]+)$") + local icon = process_icons[process_name] or wezterm.nerdfonts.seti_checkbox_unchecked + + return icon +end + +-- This function returns the suggested title for a tab. +-- It prefers the title that was set via `tab:set_title()` +-- or `wezterm cli set-tab-title`, but falls back to the +-- title of the active pane in that tab. +function M.tab_title(tab_info) + local title = tab_info.tab_title + -- if the tab title is explicitly set, take that + if title and #title > 0 then + return title + end + -- Otherwise, use the title from the active pane + -- in that tab + return tab_info.active_pane.title +end + +return M