Skip to content

Instantly share code, notes, and snippets.

@Wilsonilo
Created August 24, 2024 18:27
Show Gist options
  • Save Wilsonilo/98ee4ec2d2b0bc9d1c591f5342c8cd4a to your computer and use it in GitHub Desktop.
Save Wilsonilo/98ee4ec2d2b0bc9d1c591f5342c8cd4a to your computer and use it in GitHub Desktop.
Just my Wezterm config, dirty, I ned to clean it up
-- Import the wezterm module
local wezterm = require("wezterm")
-- Session management
local session_manager = require("wezterm-session-manager/session-manager")
wezterm.on("save_session", function(window) session_manager.save_state(window) end)
wezterm.on("load_session", function(window) session_manager.load_state(window) end)
wezterm.on("restore_session", function(window) session_manager.restore_state(window) end)
-- Creates a config object which we will be adding our config to
local config = wezterm.config_builder()
-- Import our new module (put this near the top of your wezterm.lua)
local appearance = require("appearance")
-- appareance
-- if appearance.is_dark() then
-- config.color_scheme = "Tokyo Night"
-- else
-- config.color_scheme = "Tokyo Night Day"
-- end
-- the plugin is currently made for Catppuccin only
config.color_scheme = "Catppuccin Mocha"
-- then finally apply the plugin
-- these are currently the defaults:
wezterm.plugin.require("https://github.com/nekowinston/wezterm-bar").apply_to_config(config, {
position = "top",
max_width = 32,
dividers = "slant_right", -- or "slant_left", "arrows", "rounded", false
indicator = {
leader = {
enabled = true,
off = " ",
on = " ",
},
mode = {
enabled = true,
names = {
resize_mode = "RESIZE",
copy_mode = "VISUAL",
search_mode = "SEARCH",
},
},
},
tabs = {
numerals = "arabic", -- or "roman"
pane_count = "superscript", -- or "subscript", false
brackets = {
active = { "", ":" },
inactive = { "", ":" },
},
},
clock = { -- note that this overrides the whole set_right_status
enabled = false,
format = "%H:%M", -- use https://wezfurlong.org/wezterm/config/lua/wezterm.time/Time/format.html
},
})
-- Font
-- Choose your favourite font, make sure it's installed on your machine
--JetBrains Mono // Fira Code // Hack
config.font = wezterm.font({ family = "JetBrains Mono" })
-- And a font size that won't have you squinting
config.font_size = 20
config.default_cursor_style = 'BlinkingBlock'
config.animation_fps = 4
config.cursor_blink_ease_in = 'Constant'
config.cursor_blink_ease_out = 'Constant'
-- Slightly transparent and blurred background
config.window_background_opacity = 0.9
config.macos_window_background_blur = 30
-- Removes the title bar, leaving only the tab bar. Keeps
-- the ability to resize by dragging the window's edges.
-- On macOS, 'RESIZE|INTEGRATED_BUTTONS' also looks nice if
-- you want to keep the window controls visible and integrate
-- them into the tab bar.
config.window_decorations = 'RESIZE|INTEGRATED_BUTTONS'
-- Sets the font for the window frame (tab bar)
config.window_frame = {
-- Berkeley Mono for me again, though an idea could be to try a
-- serif font here instead of monospace for a nicer look?
font = wezterm.font({ family = "Berkeley Mono", weight = "Bold" }),
--font = wezterm.font 'JetBrains Mono',
font_size = 18,
}
-- Start in full screen but windowed mode
config.initial_cols = 145
config.initial_rows = 50
config.native_macos_fullscreen_mode = false
-- Function to get the current Git branch with improved error handling
local function get_git_branch()
local success, stdout, stderr = wezterm.run_child_process({"git", "rev-parse", "--abbrev-ref", "HEAD"})
if success then
local branch = stdout:gsub("\n", "") -- Remove newline character
if branch ~= "" then
return branch
else
wezterm.log_info("Git branch is empty")
return nil
end
else
wezterm.log_info("Not in a git repository")
return nil
end
end
-- Function to get the current directory name with improved root directory handling
local function get_current_directory()
local success, stdout, stderr = wezterm.run_child_process({"pwd"})
if success then
local full_path = stdout:gsub("\n", "") -- Remove newline character
if full_path == "/" then
return "/" -- Root directory
else
local dir_name = full_path:match("([^/]+)$") -- Get the last part of the path
if dir_name then
return dir_name
else
wezterm.log_info("Failed to extract directory name from: " .. full_path)
return full_path -- Return full path if we can't extract the directory name
end
end
else
wezterm.log_info("pwd command failed: " .. stderr)
return "N/A"
end
end
-- Function to get system load average
local function get_load_average()
local success, stdout, stderr = wezterm.run_child_process({"uptime"})
if success then
local load = stdout:match("load averages: ([%d%.]+)")
return load or "N/A"
else
return "N/A"
end
end
-- Function to get battery percentage (macOS specific)
local function get_battery_percentage()
local success, stdout, stderr = wezterm.run_child_process({"pmset", "-g", "batt"})
if success then
local percentage = stdout:match("(%d+)%%")
return percentage and percentage .. "%" or "N/A"
else
return "N/A"
end
end
local function segments_for_right_status(window, pane)
local git_branch = get_git_branch()
local current_dir = get_current_directory()
wezterm.log_info("Git branch: " .. (git_branch or "Not a Git repository"))
wezterm.log_info("Current directory: " .. current_dir)
return {
-- git_branch and "Git: " .. git_branch or "No Git",
-- "Dir: " .. current_dir,
-- "Load: " .. get_load_average(),
-- "Batt: " .. get_battery_percentage(),
wezterm.strftime('%a %b %-d %H:%M'),
wezterm.hostname(),
}
end
wezterm.on("save_session", function(window)
wezterm.log_info("save_session event triggered")
session_manager.save_state(window)
end)
wezterm.on("load_session", function(window)
wezterm.log_info("load_session event triggered")
session_manager.load_state(window)
end)
wezterm.on("restore_session", function(window)
wezterm.log_info("restore_session event triggered")
session_manager.restore_state(window)
end)
wezterm.on('leader-changed', function(window, pane, leader_active)
wezterm.log_info("Leader " .. (leader_active and "activated" or "deactivated"))
end)
-- Table mapping keypresses to actions
config.keys = {
{key = "s", mods = "LEADER", action = wezterm.action{EmitEvent = "save_session"}},
{key = "S", mods = "LEADER", action = wezterm.action{EmitEvent = "save_session"}},
{key = "l", mods = "LEADER", action = wezterm.action{EmitEvent = "load_session"}},
{key = "L", mods = "LEADER", action = wezterm.action{EmitEvent = "load_session"}},
{key = "r", mods = "LEADER", action = wezterm.action{EmitEvent = "restore_session"}},
{key = "R", mods = "LEADER", action = wezterm.action{EmitEvent = "restore_session"}},
-- Sends ESC + b and ESC + f sequence, which is used
-- for telling your shell to jump back/forward.
{
-- When the left arrow is pressed
key = 'LeftArrow',
-- With the "Option" key modifier held down
mods = 'OPT',
-- Perform this action, in this case - sending ESC + B
-- to the terminal
action = wezterm.action.SendString '\x1bb',
},
{
key = 'RightArrow',
mods = 'OPT',
action = wezterm.action.SendString '\x1bf',
},
{
-- I'm used to tmux bindings, so am using the quotes (") key to
-- split horizontally, and the percent (%) key to split vertically.
key = 'd',
-- Note that instead of a key modifier mapped to a key on your keyboard
-- like CTRL or ALT, we can use the LEADER modifier instead.
-- This means that this binding will be invoked when you press the leader
-- (CTRL + A), quickly followed by quotes (").
mods = 'CTRL',
action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' },
},
{
key = 'D',
mods = 'CTRL',
action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' },
},
{
key = 'W',
mods = 'CTRL',
action = wezterm.action.CloseCurrentPane { confirm = true },
},
{
-- I like to use vim direction keybindings, but feel free to replace
-- with directional arrows instead.
key = 'j', -- or DownArrow
mods = 'CTRL',
action = wezterm.action.ActivatePaneDirection('Down'),
},
{
key = 'k', -- or UpArrow
mods = 'CTRL',
action = wezterm.action.ActivatePaneDirection('Up'),
},
{
key = 'h', -- or LeftArrow
mods = 'CTRL',
action = wezterm.action.ActivatePaneDirection('Left'),
},
{
key = 'l', -- or RightArrow
mods = 'CTRL',
action = wezterm.action.ActivatePaneDirection('Right'),
}
}
config.leader = { key = 'a', mods = 'CMD', timeout_milliseconds = 1000 }
-- Returns our config to be evaluated. We must always do this at the bottom of this file
return config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment