Skip to content

Instantly share code, notes, and snippets.

@ilaborie
Last active November 25, 2023 10:58
Show Gist options
  • Save ilaborie/42ab0e124dba544125c2b3f81d59ee61 to your computer and use it in GitHub Desktop.
Save ilaborie/42ab0e124dba544125c2b3f81d59ee61 to your computer and use it in GitHub Desktop.
Wezterm configuration
-- Pull in the wezterm API
local wezterm = require 'wezterm'
-- This table will hold the configuration.
local config = {}
-- In newer versions of wezterm, use the config_builder which will
-- help provide clearer error messages
if wezterm.config_builder then
config = wezterm.config_builder()
end
config.default_prog = { '/opt/homebrew/bin/fish', '-l' }
-- Themes
-- See <https://wezfurlong.org/wezterm/colorschemes/>
config.color_scheme = 'Catppuccin Mocha'
-- config.color_scheme = 'Ayu Mirage'
-- 'Adventure'
-- 'AdventureTime'
-- 'Afterglow (Gogh)'
-- 'Afterglow'
-- 'Ayu Mirage'
-- 'Chalk'
-- 'Panda (Gogh)'
config.use_fancy_tab_bar = false
config.hide_tab_bar_if_only_one_tab = false
-- Font
-- config.font = wezterm.font 'Inconsolata Nerd Font Mono'
config.font_size = 18.0
config.command_palette_font_size = 24.0
config.adjust_window_size_when_changing_font_size = false
config.native_macos_fullscreen_mode = true
config.enable_scroll_bar = true
config.tab_max_width = 30
-- Keymap
local act = wezterm.action
config.keys = {
{ key = 'LeftArrow', mods = 'CMD|SHIFT', action = act.ActivateTabRelative(-1) },
{ key = 'RightArrow', mods = 'CMD|SHIFT', action = act.ActivateTabRelative(1) },
{ key = 'LeftArrow', mods = 'OPT', action = act.SendString '\x1bb' },
{ key = 'RightArrow', mods = 'OPT', action = act.SendString '\x1bf' },
-- Command palette
{ key = 'P', mods = 'CMD|SHIFT', action = act.ActivateCommandPalette },
-- Panes
{ key = 'W', mods = 'ALT|SHIFT', action = act.CloseCurrentPane { confirm = false } },
{ key = 'H', mods = 'ALT|SHIFT', action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' } },
{ key = 'V', mods = 'ALT|SHIFT', action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' } },
{ key = 'LeftArrow', mods = 'ALT|SHIFT' , action = act.ActivatePaneDirection 'Left' },
{ key = 'RightArrow', mods = 'ALT|SHIFT' , action = act.ActivatePaneDirection 'Right' },
{ key = 'UpArrow', mods = 'ALT|SHIFT' , action = act.ActivatePaneDirection 'Up' },
{ key = 'DownArrow', mods = 'ALT|SHIFT' , action = act.ActivatePaneDirection 'Down' },
}
-- Bell
config.audible_bell = "Disabled"
config.visual_bell = {
fade_in_duration_ms = 75,
fade_out_duration_ms = 75,
}
config.colors = {
visual_bell = '#be9f59',
}
-- Display time
wezterm.on('update-right-status', function(window)
-- "Wed Mar 3 08:14"
local date = wezterm.strftime '%a %b %-d %H:%M '
window:set_right_status(wezterm.format {
{ Attribute = { Intensity = 'Bold' } },
{ Text = wezterm.nerdfonts.mdi_clock .. ' ' .. date },
})
end)
local function get_current_working_dir(tab)
local current_dir = tab.active_pane.current_working_dir
local HOME_DIR = string.format('file://%s', os.getenv('HOME'))
return current_dir == HOME_DIR and '.'
or string.gsub(current_dir, '(.*[/\\])(.*)', '%2')
end
local process_icons = {
['docker'] = {
{ Text = wezterm.nerdfonts.linux_docker },
},
['docker-compose'] = {
{ Text = wezterm.nerdfonts.linux_docker },
},
['kuberlr'] = {
{ Text = wezterm.nerdfonts.linux_docker },
},
['kubectl'] = {
{ Text = wezterm.nerdfonts.linux_docker },
},
['nvim'] = {
{ Text = wezterm.nerdfonts.custom_vim },
},
['vim'] = {
{ Text = wezterm.nerdfonts.dev_vim },
},
['node'] = {
{ Text = wezterm.nerdfonts.mdi_hexagon },
},
['zsh'] = {
{ Text = wezterm.nerdfonts.dev_terminal },
},
['bash'] = {
{ Text = wezterm.nerdfonts.cod_terminal_bash },
},
['btm'] = {
{ Text = wezterm.nerdfonts.mdi_chart_donut_variant },
},
['htop'] = {
{ Text = wezterm.nerdfonts.mdi_chart_donut_variant },
},
['cargo'] = {
{ Text = wezterm.nerdfonts.dev_rust },
},
['go'] = {
{ Text = wezterm.nerdfonts.mdi_language_go },
},
['lazydocker'] = {
{ Text = wezterm.nerdfonts.linux_docker },
},
['git'] = {
{ Text = wezterm.nerdfonts.dev_git },
},
['lua'] = {
{ Text = wezterm.nerdfonts.seti_lua },
},
['wget'] = {
{ Text = wezterm.nerdfonts.mdi_arrow_down_box },
},
['curl'] = {
{ Text = wezterm.nerdfonts.mdi_flattr },
},
['gh'] = {
{ Text = wezterm.nerdfonts.dev_github_badge },
},
}
local function get_process(tab)
local process_name = string.gsub(tab.active_pane.foreground_process_name, '(.*[/\\])(.*)', '%2')
if string.find(process_name, 'kubectl') then
process_name = 'kubectl'
end
return wezterm.format(
process_icons[process_name]
or { { Text = string.format('[%s]', process_name) } }
)
end
wezterm.on(
'format-tab-title',
function(tab, tabs, panes, config, hover, max_width)
return wezterm.format({
{ Attribute = { Intensity = 'Half' } },
{ Text = string.format(' %s ', wezterm.nerdfonts.fa_chevron_right) },
'ResetAttributes',
-- { Text = get_process(tab) },
-- { Text = ' ~ ' },
{ Text = get_current_working_dir(tab) },
{ Text = ' ' },
})
end
)
return config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment