Skip to content

Instantly share code, notes, and snippets.

@higemaru
Last active October 3, 2024 13:43
Show Gist options
  • Save higemaru/2ef492c34ac0daf03f18d528fdeb248d to your computer and use it in GitHub Desktop.
Save higemaru/2ef492c34ac0daf03f18d528fdeb248d to your computer and use it in GitHub Desktop.
wezterm 20241003
-- Pull in the wezterm API
local wezterm = require 'wezterm'
--wezterm.log_info(os.getenv());
-- This will hold the configuration.
local config = {}
if wezterm.config_builder then
config = wezterm.config_builder()
end
-- This is where you actually apply your config choices
--
-- 基本
--
-- 新規ウィンドウのサイズ
config.initial_cols = 120
config.initial_rows = 30
-- WezTerm 自動アップデート
config.check_for_updates = true
config.check_for_updates_interval_seconds = 86400
-- コンフィグ変更時、即時反映
config.automatically_reload_config = true
--スクロールバーを有効にする
config.enable_scroll_bar = true
-- スクロールバッファ行数
config.scrollback_lines = 10000
-- IME 有効化
config.use_ime = true
config.exit_behavior = 'Close' -- Hold, CloseOnCleanExit
config.exit_behavior_messaging = 'Verbose' -- None, Terse
-- IME ON の時の CTRL-H 対策
config.macos_forward_to_ime_modifier_mask = 'SHIFT|CTRL'
-- ベル
config.audible_bell = 'Disabled'
-- ビジブルベル
-- https://wezfurlong.org/wezterm/config/lua/config/visual_bell.html
config.visual_bell = {
fade_in_function = 'EaseIn',
fade_in_duration_ms = 50,
fade_out_function = 'EaseOut',
fade_out_duration_ms = 50,
}
--
-- 見た目
-- https://wezfurlong.org/wezterm/config/appearance.html
--
-- based 'iceberg-dark'
--[[
-- カラースキーム
local my_scheme = wezterm.color.get_builtin_schemes()['iceberg-dark']
my_scheme.cursor_bg = '#c6c8d1'
my_scheme.cursor_fg = '#161821'
my_scheme.cursor_border = '#c6c8d1'
my_scheme.foreground = '#c6c8d1'
my_scheme.selection_bg = '#84a0c6'
my_scheme.scrollbar_thumb = '#6b7089'
my_scheme.split = '#6b7089'
config.color_schemes = {
['iceberg-dark'] = my_scheme,
}
config.color_scheme = 'iceberg-dark'
]]
config.colors = {
ansi = {
'#1e2132',
'#e27878',
'#b4be82',
'#e2a478',
'#84a0c6',
'#a093c7',
'#89b8c2',
'#c6c8d1',
},
brights = {
'#6b7089',
'#e98989',
'#c0ca8e',
'#e9b189',
'#91acd1',
'#ada0d3',
'#95c4ce',
'#d2d4de',
},
background = '#161821',
cursor_bg = '#c6c8d1',
cursor_border = '#c6c8d1',
cursor_fg = '#161821',
foreground = '#c6c8d1',
indexed = {},
selection_bg = '#84a0c6',
selection_fg = '#161821',
scrollbar_thumb = '#6b7089',
split = '#6b7089',
visual_bell = '#31445d',
}
config.default_cursor_style = 'SteadyBlock'
-- BlinkingBlock, SteadyUnderline, BlinkingUnderline, SteadyBar, BlinkingBar
-- 背景透過とぼかし
config.window_background_opacity = 0.85
config.macos_window_background_blur =4
-- タイトルバー非表示
config.window_decorations = 'RESIZE'
--config.hide_tab_bar_if_only_one_tab = true
-- タブ追加の「+」を非表示
config.show_new_tab_button_in_tab_bar = false
-- 非アクティブなペインの彩度と明度を落とす
config.inactive_pane_hsb = {
saturation = 0.5,
brightness = 0.2,
}
-- フォント
-- $ wezterm ls-fonts --list-system
-- https://wezfurlong.org/wezterm/config/lua/config/adjust_window_size_when_changing_font_size.html
config.font_size = 14
config.font =
wezterm.font("Explex", {weight="Regular", stretch="Normal", style="Normal"}) -- /Users/higemaru/Library/Fonts/Explex-Regular.ttf, CoreText
adjust_window_size_when_changing_font_size = false
-- タブの横にホスト名とカレントディレクトリを表示
-- https://wezfurlong.org/wezterm/config/lua/window/set_right_status.html
wezterm.on('update-status', function(window, pane)
local cells = {}
-- Figure out the cwd and host of the current pane.
-- This will pick up the hostname for the remote host if your
-- shell is using OSC 7 on the remote host.
local cwd_uri = pane:get_current_working_dir()
if cwd_uri then
local cwd = ''
local hostname = ''
if type(cwd_uri) == 'userdata' then
-- Running on a newer version of wezterm and we have
-- a URL object here, making this simple!
cwd = cwd_uri.file_path
hostname = cwd_uri.host or wezterm.hostname()
else
-- an older version of wezterm, 20230712-072601-f4abf8fd or earlier,
-- which doesn't have the Url object
cwd_uri = cwd_uri:sub(8)
local slash = cwd_uri:find '/'
if slash then
hostname = cwd_uri:sub(1, slash - 1)
-- and extract the cwd from the uri, decoding %-encoding
cwd = cwd_uri:sub(slash):gsub('%%(%x%x)', function(hex)
return string.char(tonumber(hex, 16))
end)
end
end
-- Remove the domain name portion of the hostname
local dot = hostname:find '[.]'
if dot then
hostname = hostname:sub(1, dot - 1)
end
if hostname == '' then
hostname = wezterm.hostname()
end
local homedir = os.getenv('HOME') or ''
if homedir ~= '' then
cwd = string.gsub(cwd, homedir, '~')
end
table.insert(cells, cwd)
table.insert(cells, hostname)
end
-- UserName
local username = os.getenv('USER') or os.getenv('LOGNAME') or os.getenv('USERNAME')
table.insert(cells, username)
-- An entry for each battery (typically 0 or 1 battery)
for _, b in ipairs(wezterm.battery_info()) do
table.insert(cells, string.format('%.0f%%', b.state_of_charge * 100))
end
local wdays = {'日','月','火','水','木','金','土'}
local date = wezterm.strftime '%Y/%m/%d'
local wday = wezterm.strftime '%w'
table.insert(cells, date .. '(' .. wdays[wday+1] .. ')' )
-- The powerline < symbol
local LEFT_ARROW = utf8.char(0xe0b3)
-- The filled in variant of the < symbol
local SOLID_LEFT_ARROW = utf8.char(0xe0b2)
-- Color palette for the backgrounds of each cell
local colors = {
'#333333',
'#163769',
'#436597',
'#7087b4',
'#333333',
}
-- Foreground color for the text across the fade
local text_fg = '#c0c0c0'
-- The elements to be formatted
local elements = {}
-- How many cells have been formatted
local num_cells = 0
-- Translate a cell into elements
function push(text, is_last)
local cell_no = num_cells + 1
table.insert(elements, { Foreground = { Color = text_fg } })
table.insert(elements, { Background = { Color = colors[cell_no] } })
table.insert(elements, { Text = ' ' .. text .. ' ' })
if not is_last then
table.insert(elements, { Foreground = { Color = colors[cell_no + 1] } })
table.insert(elements, { Text = SOLID_LEFT_ARROW })
end
num_cells = num_cells + 1
end
while #cells > 0 do
local cell = table.remove(cells, 1)
push(cell, #cells == 0)
end
window:set_right_status(wezterm.format(elements))
end)
--
-- キーボードショートカット
-- $ wezterm show-keys --lua
--
local act = wezterm.action
config.keys = {
-- Emacs で C-/ で undo を使いたいので
{
key = '/',
mods = 'CTRL',
action = wezterm.action{SendString='\x1f'}
},
-- フルスクリーン (トグル)
{
key = 'f',
mods = 'CTRL|CMD',
action = act.ToggleFullScreen,
},
-- 画面分割 (下)
{
key = ',',
mods = 'SUPER|CTRL',
action = act { SplitVertical = { domain = 'CurrentPaneDomain' } },
},
-- 画面分割 (右)
{
key = '.',
mods = 'SUPER|CTRL',
action = act { SplitHorizontal = { domain = 'CurrentPaneDomain' } },
},
-- ペイン間移動
{
key = 'h',
mods = 'SUPER|CTRL',
action = act.ActivatePaneDirection 'Left',
},
{
key = 'j',
mods = 'SUPER|CTRL',
action = act.ActivatePaneDirection 'Down',
},
{
key = 'k',
mods = 'SUPER|CTRL',
action = act.ActivatePaneDirection 'Up',
},
{
key = 'l',
mods = 'SUPER|CTRL',
action = act.ActivatePaneDirection 'Right',
},
-- Copy Mode
{
key = 'c',
mods = 'SUPER|CTRL',
action = act.ActivateCopyMode,
},
}
-- and finally, return the configuration to wezterm
return config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment