Skip to content

Linux/MacOS/Windows $HOME/.config/wezterm/wezterm.lua

local wezterm = require 'wezterm'
return {
    font = wezterm.font 'Maple Mono NF CN',
    window_background_opacity = 0.9,
    enable_wayland = false,
}
local wezterm = require 'wezterm'
return {
    font = wezterm.font_with_fallback({
        { family = "Maple Mono NF CN",  weight = "Regular", italic = false },
        { family = "JetBrainsMono NF",  weight = "Regular", italic = false },
        { family = "HarmonyOS Sans SC", weight = "Regular", italic = false },
    }),
    colors = (function()
        local materia = wezterm.color.get_builtin_schemes()['Material Darker (base16)']
        materia.scrollbar_thumb = '#cccccc' -- 更明显的滚动条
        return materia
    end)(),
    font_size = 12.0,
    initial_cols = 96,
    initial_rows = 24,

    enable_wayland = false,

    window_background_opacity = 0.9,
    window_close_confirmation = 'NeverPrompt',
    window_decorations = "INTEGRATED_BUTTONS|RESIZE",
    window_padding = { left = 0, right = 15, top = 0, bottom = 0 },
    enable_scroll_bar = true,



    default_prog = (function()
        if wezterm.target_triple == "x86_64-pc-windows-msvc" then
            -- Windows 默认用 PowerShell
            return { 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe' }
        else
            -- Linux/macOS 优先 zsh, 否则 bash
            local function exists(cmd)
                return wezterm.run_child_process({ 'sh', '-c', 'command -v ' .. cmd }) == 0
            end
            if exists('zsh') then
                return { 'zsh' }
            elseif exists('bash') then
                return { 'bash' }
            else
                return { os.getenv('SHELL') or '/bin/sh' }
            end
        end
    end)(),
    launch_menu = (function()
        local menu = {}
        if wezterm.target_triple == "x86_64-pc-windows-msvc" then
            table.insert(menu,
                { label = 'MINGW64 / MSYS2', args = { 'C:/msys64/msys2_shell.cmd', '-defterm', '-here', '-no-start', '-shell', 'zsh', '-mingw64' }, })
            table.insert(menu,
                { label = 'MSYS / MSYS2', args = { 'C:/msys64/msys2_shell.cmd', '-defterm', '-here', '-no-start', '-shell', 'zsh', '-msys' }, })
            table.insert(menu,
                { label = 'PowerShell', args = { 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe' }, })
            table.insert(menu, { label = 'CMD', args = { 'cmd.exe' }, })
            table.insert(menu, { label = 'nas / ssh', args = { 'C:/msys64/usr/bin/ssh.exe', 'nas' }, })
        else
            -- Linux/macOS 下提供 bash/zsh 选项
            if wezterm.run_child_process({ 'sh', '-c', 'command -v zsh' }) == 0 then
                table.insert(menu, { label = 'zsh', args = { 'zsh' } })
            end
            if wezterm.run_child_process({ 'sh', '-c', 'command -v bash' }) == 0 then
                table.insert(menu, { label = 'bash', args = { 'bash' } })
            end
            table.insert(menu, { label = 'sh', args = { '/bin/sh' } })
        end
        return menu
    end)(),


    -- 取消所有默认的热键
    -- disable_default_key_bindings = true,
    keys = (function()
        local act = wezterm.action
        return {
            -- Ctrl+Shift+Tab 遍历 tab
            { key = 'Tab',       mods = 'SHIFT|CTRL', action = act.ActivateTabRelative(1) },
            -- F11 切换全屏
            { key = 'F11',       mods = 'NONE',       action = act.ToggleFullScreen },
            -- Ctrl+Shift++ 字体增大
            { key = '+',         mods = 'SHIFT|CTRL', action = act.IncreaseFontSize },
            -- Ctrl+Shift+- 字体减小
            { key = '_',         mods = 'SHIFT|CTRL', action = act.DecreaseFontSize },
            -- Ctrl+Shift+C 复制选中区域
            { key = 'C',         mods = 'SHIFT|CTRL', action = act.CopyTo 'Clipboard' },
            -- Ctrl+Shift+N 新窗口
            { key = 'N',         mods = 'SHIFT|CTRL', action = act.SpawnWindow },
            -- Ctrl+Shift+T 新 tab
            { key = 'T',         mods = 'SHIFT|CTRL', action = act.ShowLauncher },
            -- Ctrl+Shift+Enter 显示启动菜单
            { key = 'Enter',     mods = 'SHIFT|CTRL', action = act.ShowLauncherArgs { flags = 'FUZZY|TABS|LAUNCH_MENU_ITEMS' } },
            -- Ctrl+Shift+V 粘贴剪切板的内容
            { key = 'V',         mods = 'SHIFT|CTRL', action = act.PasteFrom 'Clipboard' },
            -- Ctrl+Shift+W 关闭 tab 且不进行确认
            { key = 'W',         mods = 'SHIFT|CTRL', action = act.CloseCurrentTab { confirm = false } },
            -- Ctrl+Shift+PageUp 向上滚动一页
            { key = 'PageUp',    mods = 'SHIFT|CTRL', action = act.ScrollByPage(-1) },
            -- Ctrl+Shift+PageDown 向下滚动一页
            { key = 'PageDown',  mods = 'SHIFT|CTRL', action = act.ScrollByPage(1) },
            -- Ctrl+Shift+UpArrow 向上滚动一行
            { key = 'UpArrow',   mods = 'SHIFT|CTRL', action = act.ScrollByLine(-1) },
            -- Ctrl+Shift+DownArrow 向下滚动一行
            { key = 'DownArrow', mods = 'SHIFT|CTRL', action = act.ScrollByLine(1) },
        }
    end)(),
}