Skip to content

Commit

Permalink
feat(wezterm): move events to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
sbulav committed Feb 8, 2024
1 parent 8fabc1f commit 2aefdfa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
1 change: 1 addition & 0 deletions nix/modules/nixos/desktop/addons/wezterm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ in {
+ (builtins.readFile ./mappings.lua)
+ (builtins.readFile ./colors.lua)
+ (builtins.readFile ./tabs.lua)
+ (builtins.readFile ./events.lua)
+ ''
return config
'';
Expand Down
35 changes: 35 additions & 0 deletions nix/modules/nixos/desktop/addons/wezterm/events.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Update window title
-- {{{
wezterm.on("format-window-title", function(tab, _, tabs)
local index = ""
if #tabs > 1 then
index = "[" .. tab.tab_index + 1 .. "/" .. #tabs .. "]"
end

return index .. tab.window_title
end)
-- }}}
-- Update status on the right side
-- {{{
-- Icons: https://wezfurlong.org/wezterm/config/lua/wezterm/nerdfonts.html
-- https://wezfurlong.org/wezterm/config/lua/window-events/update-right-status.html
wezterm.on("update-right-status", function(window)
local _, kube_context, _ = wezterm.run_child_process { "bash", "-lc", "kubectx -c" }
local _, kube_ns, _ = wezterm.run_child_process { "bash", "-lc", "kubens -c" }
kube_context = kube_context:gsub("[\n\r]", "")
kube_ns = kube_ns:gsub("[\n\r]", "")

local date = wezterm.strftime "[%H:%M]"

window:set_right_status(wezterm.format {
{ Foreground = { Color = base16_colors.blue } },
{ Text = wezterm.nerdfonts.md_kubernetes },
{ Foreground = { Color = base16_colors.magenta } },
{ Text = " " .. kube_context },
{ Foreground = { Color = base16_colors.cyan } },
{ Text = ":" .. kube_ns },
{ Foreground = { Color = base16_colors.red } },
{ Text = " " .. date },
})
end)
-- }}}
35 changes: 0 additions & 35 deletions nix/modules/nixos/desktop/addons/wezterm/wezterm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,3 @@ config.inactive_pane_hsb = {
brightness = 0.2,
}
-- }}}
-- Update window title
-- {{{
wezterm.on("format-window-title", function(tab, _, tabs)
local index = ""
if #tabs > 1 then
index = "[" .. tab.tab_index + 1 .. "/" .. #tabs .. "]"
end

return index .. tab.window_title
end)
-- }}}
-- Update status on the right side
-- {{{
-- Icons: https://wezfurlong.org/wezterm/config/lua/wezterm/nerdfonts.html
-- https://wezfurlong.org/wezterm/config/lua/window-events/update-right-status.html
wezterm.on("update-right-status", function(window)
local _, kube_context, _ = wezterm.run_child_process { "bash", "-lc", "kubectx -c" }
local _, kube_ns, _ = wezterm.run_child_process { "bash", "-lc", "kubens -c" }
kube_context = kube_context:gsub("[\n\r]", "")
kube_ns = kube_ns:gsub("[\n\r]", "")

local date = wezterm.strftime "[%H:%M]"

window:set_right_status(wezterm.format {
{ Foreground = { Color = base16_colors.blue } },
{ Text = wezterm.nerdfonts.md_kubernetes },
{ Foreground = { Color = base16_colors.magenta } },
{ Text = " " .. kube_context },
{ Foreground = { Color = base16_colors.cyan } },
{ Text = ":" .. kube_ns },
{ Foreground = { Color = base16_colors.red } },
{ Text = " " .. date },
})
end)
-- }}}

0 comments on commit 2aefdfa

Please sign in to comment.