mcpField
W
wezterm

wezterm

github.com/johnlindquist开发2657 次安装45 周前更新
代码仓库

关于 wezterm

wezterm 是用于配置 WezTerm 终端模拟器的技能,面向希望定制终端环境的用户。它提供 Lua 配置示例,涉及字体、配色、快捷键、标签栏、启动布局、SSH 域和多路复用器。

主要功能

  1. 01配置字体与备用字体
  2. 02设置配色方案和自定义颜色
  3. 03定义快捷键、分屏与标签
  4. 04配置启动布局和 SSH 域
  5. 05使用多路复用器管理会话
  6. 06自定义状态栏与背景图

适用场景

  1. 01设置终端字体和主题
  2. 02配置快捷键与分屏导航
  3. 03启动时打开预设窗格布局
  4. 04连接 SSH 域或持久会话

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/johnlindquist/claude --skill wezterm

安装后在 Claude Code 中输入/wezterm确认已加载。

详细介绍

WezTerm 配置

配置 WezTerm 终端模拟器。

前置要求

# Install WezTerm
brew install --cask wezterm

配置文件位置:~/.wezterm.lua 或 ~/.config/wezterm/wezterm.lua

基础配置

最小配置
-- ~/.wezterm.lua
local wezterm = require 'wezterm'
local config = wezterm.config_builder()

-- Font
config.font = wezterm.font('JetBrains Mono')
config.font_size = 14.0

-- Colors
config.color_scheme = 'Catppuccin Mocha'

-- Window
config.window_padding = {
  left = 10,
  right = 10,
  top = 10,
  bottom = 10,
}

return config
字体配置
-- Single font
config.font = wezterm.font('JetBrains Mono')

-- Font with fallbacks
config.font = wezterm.font_with_fallback({
  'JetBrains Mono',
  'Fira Code',
  'Nerd Font Symbols',
})

-- Font with weight
config.font = wezterm.font('JetBrains Mono', { weight = 'Medium' })

-- Different font for bold
config.font_rules = {
  {
    intensity = 'Bold',
    font = wezterm.font('JetBrains Mono', { weight = 'Bold' }),
  },
}
配色方案
-- Use built-in scheme
config.color_scheme = 'Catppuccin Mocha'

-- List available schemes
-- wezterm show-keys --lua

-- Custom colors
config.colors = {
  foreground = '#c0caf5',
  background = '#1a1b26',
  cursor_bg = '#c0caf5',
  selection_bg = '#33467c',
  ansi = {'#15161e', '#f7768e', '#9ece6a', '#e0af68', '#7aa2f7', '#bb9af7', '#7dcfff', '#a9b1d6'},
  brights = {'#414868', '#f7768e', '#9ece6a', '#e0af68', '#7aa2f7', '#bb9af7', '#7dcfff', '#c0caf5'},
}

快捷键绑定

自定义快捷键
config.keys = {
  -- Split panes
  { key = 'd', mods = 'CMD', action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' } },
  { key = 'd', mods = 'CMD|SHIFT', action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' } },

  -- Navigate panes
  { key = 'LeftArrow', mods = 'CMD', action = wezterm.action.ActivatePaneDirection 'Left' },
  { key = 'RightArrow', mods = 'CMD', action = wezterm.action.ActivatePaneDirection 'Right' },
  { key = 'UpArrow', mods = 'CMD', action = wezterm.action.ActivatePaneDirection 'Up' },
  { key = 'DownArrow', mods = 'CMD', action = wezterm.action.ActivatePaneDirection 'Down' },

  -- Tabs
  { key = 't', mods = 'CMD', action = wezterm.action.SpawnTab 'CurrentPaneDomain' },
  { key = 'w', mods = 'CMD', action = wezterm.action.CloseCurrentPane { confirm = true } },

  -- Font size
  { key = '=', mods = 'CMD', action = wezterm.action.IncreaseFontSize },
  { key = '-', mods = 'CMD', action = wezterm.action.DecreaseFontSize },
  { key = '0', mods = 'CMD', action = wezterm.action.ResetFontSize },
}
Leader 键
-- Define leader key (like tmux prefix)
config.leader = { key = 'a', mods = 'CMD', timeout_milliseconds = 1000 }

config.keys = {
  -- Leader + c = new tab
  { key = 'c', mods = 'LEADER', action = wezterm.action.SpawnTab 'CurrentPaneDomain' },
  -- Leader + | = vertical split
  { key = '|', mods = 'LEADER', action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' } },
  -- Leader + - = horizontal split
  { key = '-', mods = 'LEADER', action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' } },
}

高级功能

标签栏自定义
config.use_fancy_tab_bar = false
config.tab_bar_at_bottom = true
config.hide_tab_bar_if_only_one_tab = true

-- Custom tab title
wezterm.on('format-tab-title', function(tab)
  local title = tab.tab_title
  if title and #title > 0 then
    return title
  end
  return tab.active_pane.title
end)
启动操作
-- Start with specific layout
wezterm.on('gui-startup', function(cmd)
  local tab, pane, window = mux.spawn_window(cmd or {})
  -- Split right
  pane:split { direction = 'Right' }
end)
SSH 域
config.ssh_domains = {
  {
    name = 'my-server',
    remote_address = 'server.example.com',
    username = 'user',
  },
}

-- Connect with: wezterm connect my-server
多路复用器
-- Unix domain for persistent sessions
config.unix_domains = {
  { name = 'unix' },
}

-- Default to multiplexer
config.default_gui_startup_args = { 'connect', 'unix' }

实用代码片段

快速切换主题
local function toggle_theme()
  local overrides = window:get_config_overrides() or {}
  if overrides.color_scheme == 'Catppuccin Latte' then
    overrides.color_scheme = 'Catppuccin Mocha'
  else
    overrides.color_scheme = 'Catppuccin Latte'
  end
  window:set_config_overrides(overrides)
end

config.keys = {
  { key = 't', mods = 'CMD|SHIFT', action = wezterm.action_callback(toggle_theme) },
}
背景图片
config.window_background_image = '/path/to/image.png'
config.window_background_image_hsb = {
  brightness = 0.02,
  saturation = 0.5,
}
状态栏
wezterm.on('update-right-status', function(window, pane)
  window:set_right_status(wezterm.format({
    { Text = wezterm.strftime('%H:%M') },
  }))
end)

命令行

# Open with specific config
wezterm --config-file path/to/config.lua

# Connect to multiplexer
wezterm connect unix

# List color schemes
wezterm ls-colors

# Show key bindings
wezterm show-keys
wezterm show-keys --lua

# CLI utilities
wezterm cli list           # List panes
wezterm cli spawn          # Spawn new pane
wezterm cli split-pane     # Split current pane

最佳实践

  1. 从简单开始 - 按需添加功能
  2. 使用 config_builder - 获得更好的错误提示
  3. 增量测试 - WezTerm 会在保存时重新加载
  4. 备份你的配置 - 保存在 dotfiles 仓库中
  5. 使用 leader 键 - 避免与应用冲突
  6. 查看日志 - wezterm --config-file ~/.wezterm.lua 会显示错误

评论

支持 Markdown