dotfiles/terminal/.config/wezterm/statusbar.lua

48 lines
1.3 KiB
Lua
Raw Permalink Normal View History

2023-06-15 08:12:30 +00:00
local wezterm = require("wezterm")
2022-11-25 15:21:20 +00:00
2023-06-15 08:12:30 +00:00
local function basename(s)
return string.gsub(s or "", "(.*[/\\])(.*)", "%2")
end
2022-11-25 15:21:20 +00:00
2023-06-15 08:12:30 +00:00
local SEPARATOR = " | "
2022-11-25 15:21:20 +00:00
local function setup()
2023-06-15 08:12:30 +00:00
-- STATUSBAR
-- show currently active key table in lower right status bar
-- mimicing Vim modes
wezterm.on("update-status", function(window, pane)
local displayed = { left = {}, right = {} }
local keytable = window:active_key_table()
if keytable then
displayed.left[#displayed.left + 1] = "MODE: " .. keytable
end
local workspace = window:active_workspace()
if workspace and workspace ~= "default" then
displayed.left[#displayed.left + 1] = "WORKSPACE: " .. workspace
end
local bat = ""
for _, b in ipairs(wezterm.battery_info()) do
bat = "🔋 " .. string.format("%.0f%%", b.state_of_charge * 100) .. " " .. b.state
end
displayed.right[#displayed.right + 1] = bat
local currentprogram = pane:get_foreground_process_name()
displayed.right[#displayed.right + 1] = basename(currentprogram)
local statusleft = ""
for _, v in ipairs(displayed.left) do
statusleft = statusleft .. v .. SEPARATOR
end
local statusright = ""
for _, v in ipairs(displayed.right) do
statusright = statusright .. v .. SEPARATOR
end
window:set_left_status(statusleft or "")
window:set_right_status(statusright or "")
end)
2022-11-25 15:21:20 +00:00
end
return { setup = setup }