← AI開発 資料アーカイブ
環境構築セットアップ

WezTerm外観・タブ設定 wezterm.lua(フォント/透過/カスタムタブ)

元ファイル: れん君パート/wezterm.lua

要約

WezTermの外観・挙動を定義するメイン設定Luaファイル。HackGen Console NFフォント、font_size 13、行間1.2、IME有効、背景透過0.75、タイトルバー非表示、タブバーを下部表示・1枚時は非表示などを設定。format-tab-titleでタブにインデックス番号とカレントディレクトリ名を表示し、アクティブタブをアンバー系、非アクティブをグレー系に色分けする台形タブのカスタム描画を実装する。

要点

WezTermlua設定外観フォントタブ透過環境構築

local wezterm = require("wezterm")
local config = wezterm.config_builder()

config.automatically_reload_config = true
config.font = wezterm.font("HackGen Console NF", { weight = "Regular" })
config.font_size = 13.0
config.line_height = 1.2
config.use_ime = true
config.window_background_opacity = 0.75

----------------------------------------------------
-- Tab
----------------------------------------------------
-- タイトルバーを非表示
config.window_decorations = "TITLE | RESIZE"
-- タブバーの表示
config.show_tabs_in_tab_bar = true
config.tab_bar_at_bottom = true
-- タブが一つの時は非表示
config.hide_tab_bar_if_only_one_tab = true
-- falseにするとタブバーの透過が効かなくなる
-- config.use_fancy_tab_bar = false

-- タブバーの透過
config.window_frame = {
  inactive_titlebar_bg = "none",
  active_titlebar_bg = "none",
}

-- タブバーを背景色に合わせる
config.window_background_gradient = {
  colors = { "#000000" },
}

-- タブの追加ボタンを非表示
config.show_new_tab_button_in_tab_bar = false
-- nightlyのみ使用可能
-- タブの閉じるボタンを非表示
-- config.show_close_tab_button_in_tabs = false

-- タブ同士の境界線を非表示
config.colors = {
  tab_bar = {
    inactive_tab_edge = "none",
  },
}

-- タブの形をカスタマイズ
-- タブの左側の装飾
local SOLID_LEFT_ARROW = wezterm.nerdfonts.ple_lower_right_triangle
-- タブの右側の装飾
local SOLID_RIGHT_ARROW = wezterm.nerdfonts.ple_upper_left_triangle

wezterm.on("format-tab-title", function(tab, tabs, panes, config, hover, max_width)
  local background = "#5c6d74"
  local foreground = "#FFFFFF"
  local edge_background = "none"
  if tab.is_active then
    background = "#6B4F0A"
    foreground = "#FFFFFF"
  end
  local edge_foreground = background
  local tab_index = tab.tab_index + 1
  local pane_title = tab.active_pane.title
  -- カスタムタブ名が設定されていればそちらを優先
  local tab_title = tab.tab_title
  if tab_title and #tab_title > 0 then
    pane_title = tab_title
  else
    local cwd = tab.active_pane.current_working_dir
    if cwd then
      local cwd_str = cwd.file_path or tostring(cwd)
      pane_title = cwd_str:match("([^/]+)/?$") or pane_title
    end
  end
  local title = "  " .. tab_index .. ": " .. pane_title .. "  "
  return {
    { Background = { Color = edge_background } },
    { Foreground = { Color = edge_foreground } },
    { Text = SOLID_LEFT_ARROW },
    { Background = { Color = background } },
    { Foreground = { Color = foreground } },
    { Text = title },
    { Background = { Color = edge_background } },
    { Foreground = { Color = edge_foreground } },
    { Text = SOLID_RIGHT_ARROW },
  }
end)

----------------------------------------------------
-- keybinds
----------------------------------------------------
config.disable_default_key_bindings = true
config.keys = require("keybinds").keys
config.key_tables = require("keybinds").key_tables
config.leader = { key = "q", mods = "CTRL", timeout_milliseconds = 2000 }

-- ペイン境界の表示を有効化
config.inactive_pane_hsb = {
  saturation = 0.9,
  brightness = 0.8,
}

return config

↑ トップへ戻る