Skip to content

Commit

Permalink
chore: update right side
Browse files Browse the repository at this point in the history
  • Loading branch information
fisenkodv committed Mar 23, 2024
1 parent 4143bae commit f916415
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 3 deletions.
30 changes: 27 additions & 3 deletions config/wezterm/cfg_appearance.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local wezterm = require("wezterm")
local helpers = require("lib.helpers")

local M = {}

Expand All @@ -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({
Expand All @@ -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,
}
Expand All @@ -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
15 changes: 15 additions & 0 deletions config/wezterm/cfg_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
49 changes: 49 additions & 0 deletions config/wezterm/lib/helpers.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f916415

Please sign in to comment.