lua: Format with stylua

This commit is contained in:
Marty Oehme 2023-06-15 10:12:30 +02:00
parent e434c191c9
commit 5f93ecba7c
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
33 changed files with 4062 additions and 3413 deletions

View file

@ -1,75 +1,81 @@
local wezterm = require 'wezterm'
local io = require 'io'
local os = require 'os'
local wezterm = require("wezterm")
local io = require("io")
local os = require("os")
local act = wezterm.action
local function setup()
local function isViProcess(pane)
return pane:get_foreground_process_name():find('n?vim') ~= nil
end
local function isViProcess(pane)
return pane:get_foreground_process_name():find("n?vim") ~= nil
end
local function conditionalActivatePane(window, pane, pane_direction,
vim_direction)
if (isViProcess(pane)) then
window:perform_action(act.Multiple {
act.SendKey { key = 'w', mods = 'CTRL' },
act.SendKey { key = vim_direction }
}, pane)
else
window:perform_action(act.ActivatePaneDirection(pane_direction),
pane)
end
end
local function conditionalActivatePane(window, pane, pane_direction, vim_direction)
if isViProcess(pane) then
window:perform_action(
act.Multiple({
act.SendKey({ key = "w", mods = "CTRL" }),
act.SendKey({ key = vim_direction }),
}),
pane
)
else
window:perform_action(act.ActivatePaneDirection(pane_direction), pane)
end
end
wezterm.on('ActivatePaneDirection-right', function(window, pane)
conditionalActivatePane(window, pane, 'Right', 'l')
end)
wezterm.on('ActivatePaneDirection-left', function(window, pane)
conditionalActivatePane(window, pane, 'Left', 'h')
end)
wezterm.on('ActivatePaneDirection-up', function(window, pane)
conditionalActivatePane(window, pane, 'Up', 'k')
end)
wezterm.on('ActivatePaneDirection-down', function(window, pane)
conditionalActivatePane(window, pane, 'Down', 'j')
end)
wezterm.on("ActivatePaneDirection-right", function(window, pane)
conditionalActivatePane(window, pane, "Right", "l")
end)
wezterm.on("ActivatePaneDirection-left", function(window, pane)
conditionalActivatePane(window, pane, "Left", "h")
end)
wezterm.on("ActivatePaneDirection-up", function(window, pane)
conditionalActivatePane(window, pane, "Up", "k")
end)
wezterm.on("ActivatePaneDirection-down", function(window, pane)
conditionalActivatePane(window, pane, "Down", "j")
end)
-- Retrieve the current scrollback text and send to editor
wezterm.on('edit-scrollback', function(window, pane)
local viewport_text = pane:get_lines_as_text(10000)
-- Retrieve the current scrollback text and send to editor
wezterm.on("edit-scrollback", function(window, pane)
local viewport_text = pane:get_lines_as_text(10000)
-- Create a temporary file to pass to vim
local name = os.tmpname()
-- Create a temporary file to pass to vim
local name = os.tmpname()
local f = io.open(name, 'w+')
if f == nil then return false end
f:write(viewport_text)
f:flush()
f:close()
local f = io.open(name, "w+")
if f == nil then
return false
end
f:write(viewport_text)
f:flush()
f:close()
-- Open a new window running vim and tell it to open the file
window:perform_action(act.SpawnCommandInNewTab {
args = { (os.getenv('EDITOR') or 'vi'), name }
}, pane)
-- Open a new window running vim and tell it to open the file
window:perform_action(
act.SpawnCommandInNewTab({
args = { (os.getenv("EDITOR") or "vi"), name },
}),
pane
)
-- Wait time for vim to read the file before we remove it.
wezterm.sleep_ms(1000)
os.remove(name)
end)
-- Wait time for vim to read the file before we remove it.
wezterm.sleep_ms(1000)
os.remove(name)
end)
wezterm.on("toggle-leader", function(window, pane)
wezterm.log_info("toggling the leader")
local overrides = window:get_config_overrides() or {}
if not overrides.leader then
wezterm.log_info("leader wasn't set")
overrides.leader = { key = "s", mods = "SUPER" };
else
wezterm.log_info("leader was set")
overrides.leader = nil
end
wezterm.on("toggle-leader", function(window, pane)
wezterm.log_info("toggling the leader")
local overrides = window:get_config_overrides() or {}
if not overrides.leader then
wezterm.log_info("leader wasn't set")
overrides.leader = { key = "s", mods = "SUPER" }
else
wezterm.log_info("leader was set")
overrides.leader = nil
end
window:set_config_overrides(overrides)
end)
window:set_config_overrides(overrides)
end)
end
return { setup = setup }

View file

@ -1,127 +1,137 @@
local wezterm = require('wezterm')
local wezterm = require("wezterm")
local act = wezterm.action
local keys = {
{ key = 'O', mods = 'CTRL', action = act.ShowDebugOverlay },
{ key = '[', mods = 'CTRL', action = act.ScrollToPrompt(-1) },
{ key = ']', mods = 'CTRL', action = act.ScrollToPrompt(1) },
{ -- vertical pane
key = '\\',
mods = 'LEADER',
action = act.SplitHorizontal { domain = 'CurrentPaneDomain' }
}, { -- horizontal pane
key = '-',
mods = 'LEADER',
action = act.SplitVertical { domain = 'CurrentPaneDomain' }
}, -- pane movement keys
{
key = 'h',
mods = 'CTRL',
action = act.EmitEvent 'ActivatePaneDirection-left'
},
{
key = 'j',
mods = 'CTRL',
action = act.EmitEvent 'ActivatePaneDirection-down'
},
{
key = 'k',
mods = 'CTRL',
action = act.EmitEvent 'ActivatePaneDirection-up'
}, {
key = 'l',
mods = 'CTRL',
action = act.EmitEvent 'ActivatePaneDirection-right'
}, { key = 'z', mods = 'LEADER', action = act.TogglePaneZoomState },
{ key = ' ', mods = 'LEADER', action = act.RotatePanes 'Clockwise' },
{ key = 'q', mods = 'LEADER', action = act.PaneSelect { mode = 'Activate' } },
{
key = 'Q',
mods = 'LEADER',
action = act.PaneSelect { mode = 'SwapWithActive' }
}, { key = 'c', mods = 'LEADER', action = act.SpawnTab 'CurrentPaneDomain' },
{ key = ',', mods = 'LEADER', action = act.MoveTabRelative(-1) },
{ key = '.', mods = 'LEADER', action = act.MoveTabRelative(1) }, -- workspace selection
{
key = 's',
mods = 'LEADER',
action = act.ShowLauncherArgs { flags = 'FUZZY|WORKSPACES' }
}, { key = 't', mods = 'LEADER', action = act.ShowTabNavigator },
{ key = '[', mods = 'LEADER', action = act.ActivateCopyMode }, {
key = 'r',
mods = 'LEADER',
action = act.ActivateKeyTable {
name = 'resize_pane',
one_shot = false,
timeout_milliseconds = 2000,
replace_current = true
}
}, { key = 'f', mods = 'LEADER', action = act.QuickSelect }, {
key = 'F',
mods = 'LEADER',
action = wezterm.action.QuickSelectArgs {
patterns = { "https?://\\S+" },
action = wezterm.action_callback(
function(window, pane)
local url = window:get_selection_text_for_pane(pane)
wezterm.log_info("opening: " .. url)
wezterm.open_with(url)
end)
}
}, {
key = '/',
mods = 'LEADER',
action = act.Search('CurrentSelectionOrEmptyString')
}, {
key = 'b',
mods = 'LEADER',
action = act.ActivateKeyTable {
name = 'scroll_mode',
one_shot = false,
replace_current = true,
timeout_milliseconds = 15000
}
}, { key = 'e', mods = 'LEADER', action = act.EmitEvent 'edit-scrollback' },
{
key = 'l',
mods = 'LEADER',
action = act.EmitEvent 'ActivatePaneDirection-Right'
}, { key = 'a', mods = 'CTRL|ALT', action = act.EmitEvent 'toggle-leader' }
{ key = "O", mods = "CTRL", action = act.ShowDebugOverlay },
{ key = "[", mods = "CTRL", action = act.ScrollToPrompt(-1) },
{ key = "]", mods = "CTRL", action = act.ScrollToPrompt(1) },
{ -- vertical pane
key = "\\",
mods = "LEADER",
action = act.SplitHorizontal({ domain = "CurrentPaneDomain" }),
},
{ -- horizontal pane
key = "-",
mods = "LEADER",
action = act.SplitVertical({ domain = "CurrentPaneDomain" }),
}, -- pane movement keys
{
key = "h",
mods = "CTRL",
action = act.EmitEvent("ActivatePaneDirection-left"),
},
{
key = "j",
mods = "CTRL",
action = act.EmitEvent("ActivatePaneDirection-down"),
},
{
key = "k",
mods = "CTRL",
action = act.EmitEvent("ActivatePaneDirection-up"),
},
{
key = "l",
mods = "CTRL",
action = act.EmitEvent("ActivatePaneDirection-right"),
},
{ key = "z", mods = "LEADER", action = act.TogglePaneZoomState },
{ key = " ", mods = "LEADER", action = act.RotatePanes("Clockwise") },
{ key = "q", mods = "LEADER", action = act.PaneSelect({ mode = "Activate" }) },
{
key = "Q",
mods = "LEADER",
action = act.PaneSelect({ mode = "SwapWithActive" }),
},
{ key = "c", mods = "LEADER", action = act.SpawnTab("CurrentPaneDomain") },
{ key = ",", mods = "LEADER", action = act.MoveTabRelative(-1) },
{ key = ".", mods = "LEADER", action = act.MoveTabRelative(1) }, -- workspace selection
{
key = "s",
mods = "LEADER",
action = act.ShowLauncherArgs({ flags = "FUZZY|WORKSPACES" }),
},
{ key = "t", mods = "LEADER", action = act.ShowTabNavigator },
{ key = "[", mods = "LEADER", action = act.ActivateCopyMode },
{
key = "r",
mods = "LEADER",
action = act.ActivateKeyTable({
name = "resize_pane",
one_shot = false,
timeout_milliseconds = 2000,
replace_current = true,
}),
},
{ key = "f", mods = "LEADER", action = act.QuickSelect },
{
key = "F",
mods = "LEADER",
action = wezterm.action.QuickSelectArgs({
patterns = { "https?://\\S+" },
action = wezterm.action_callback(function(window, pane)
local url = window:get_selection_text_for_pane(pane)
wezterm.log_info("opening: " .. url)
wezterm.open_with(url)
end),
}),
},
{
key = "/",
mods = "LEADER",
action = act.Search("CurrentSelectionOrEmptyString"),
},
{
key = "b",
mods = "LEADER",
action = act.ActivateKeyTable({
name = "scroll_mode",
one_shot = false,
replace_current = true,
timeout_milliseconds = 15000,
}),
},
{ key = "e", mods = "LEADER", action = act.EmitEvent("edit-scrollback") },
{
key = "l",
mods = "LEADER",
action = act.EmitEvent("ActivatePaneDirection-Right"),
},
{ key = "a", mods = "CTRL|ALT", action = act.EmitEvent("toggle-leader") },
}
-- Leader + number to activate that tab
for i = 1, 8 do
table.insert(keys, {
key = tostring(i),
mods = 'LEADER',
action = act.ActivateTab(i - 1)
})
table.insert(keys, {
key = tostring(i),
mods = "LEADER",
action = act.ActivateTab(i - 1),
})
end
-- key table sub modes
local key_tables = {
-- mode to change size of any panes
resize_pane = {
{ key = 'h', action = act.AdjustPaneSize { 'Left', 1 } },
{ key = 'l', action = act.AdjustPaneSize { 'Right', 1 } },
{ key = 'k', action = act.AdjustPaneSize { 'Up', 1 } },
{ key = 'j', action = act.AdjustPaneSize { 'Down', 1 } },
{ key = 'H', action = act.AdjustPaneSize { 'Left', 10 } },
{ key = 'L', action = act.AdjustPaneSize { 'Right', 10 } },
{ key = 'K', action = act.AdjustPaneSize { 'Up', 10 } },
{ key = 'J', action = act.AdjustPaneSize { 'Down', 10 } },
{ key = 'Escape', action = 'PopKeyTable' }
},
scroll_mode = {
{ key = 'y', mods = 'CTRL', action = act.ScrollByLine(-1) },
{ key = 'e', mods = 'CTRL', action = act.ScrollByLine(1) },
{ key = 'f', mods = 'CTRL', action = act.ScrollByPage(1) },
{ key = 'b', mods = 'CTRL', action = act.ScrollByPage(-1) },
{ key = 'd', mods = 'CTRL', action = act.ScrollByPage(0.5) },
{ key = 'u', mods = 'CTRL', action = act.ScrollByPage(-0.5) },
{ key = 'g', mods = 'CTRL', action = act.ScrollToTop },
{ key = 'G', mods = 'CTRL', action = act.ScrollToBottom },
{ key = 'Escape', action = 'PopKeyTable' }
}
-- mode to change size of any panes
resize_pane = {
{ key = "h", action = act.AdjustPaneSize({ "Left", 1 }) },
{ key = "l", action = act.AdjustPaneSize({ "Right", 1 }) },
{ key = "k", action = act.AdjustPaneSize({ "Up", 1 }) },
{ key = "j", action = act.AdjustPaneSize({ "Down", 1 }) },
{ key = "H", action = act.AdjustPaneSize({ "Left", 10 }) },
{ key = "L", action = act.AdjustPaneSize({ "Right", 10 }) },
{ key = "K", action = act.AdjustPaneSize({ "Up", 10 }) },
{ key = "J", action = act.AdjustPaneSize({ "Down", 10 }) },
{ key = "Escape", action = "PopKeyTable" },
},
scroll_mode = {
{ key = "y", mods = "CTRL", action = act.ScrollByLine(-1) },
{ key = "e", mods = "CTRL", action = act.ScrollByLine(1) },
{ key = "f", mods = "CTRL", action = act.ScrollByPage(1) },
{ key = "b", mods = "CTRL", action = act.ScrollByPage(-1) },
{ key = "d", mods = "CTRL", action = act.ScrollByPage(0.5) },
{ key = "u", mods = "CTRL", action = act.ScrollByPage(-0.5) },
{ key = "g", mods = "CTRL", action = act.ScrollToTop },
{ key = "G", mods = "CTRL", action = act.ScrollToBottom },
{ key = "Escape", action = "PopKeyTable" },
},
}
return { keys = keys, key_tables = key_tables }

View file

@ -1,46 +1,47 @@
local wezterm = require 'wezterm'
local wezterm = require("wezterm")
local function basename(s) return string.gsub(s or '', '(.*[/\\])(.*)', '%2') end
local function basename(s)
return string.gsub(s or "", "(.*[/\\])(.*)", "%2")
end
local SEPARATOR = ' | '
local SEPARATOR = " | "
local function setup()
-- 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
-- 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 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 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 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
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)
window:set_left_status(statusleft or "")
window:set_right_status(statusright or "")
end)
end
return { setup = setup }

View file

@ -1,82 +1,78 @@
local wezterm = require 'wezterm'
local wezterm = require("wezterm")
local maps = require 'maps'
local maps = require("maps")
require 'statusbar'.setup()
require 'events'.setup()
require("statusbar").setup()
require("events").setup()
local function file_exists(name)
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
local f = io.open(name, "r")
if f ~= nil then
io.close(f)
return true
else
return false
end
end
-- automatically reload colors file
local colorsfile = (os.getenv('XDG_STATE_HOME') or
(os.getenv('HOME') .. '/.local/state')) ..
'/wezterm/colors.toml'
local colorsfile = (os.getenv("XDG_STATE_HOME") or (os.getenv("HOME") .. "/.local/state")) .. "/wezterm/colors.toml"
local colors = {}
if file_exists(colorsfile) == true then
wezterm.add_to_config_reload_watch_list(colorsfile)
colors = wezterm.color.load_scheme(colorsfile)
wezterm.add_to_config_reload_watch_list(colorsfile)
colors = wezterm.color.load_scheme(colorsfile)
end
local settings = {
enable_wayland = true,
hide_tab_bar_if_only_one_tab = true,
use_fancy_tab_bar = false,
tab_bar_at_bottom = true,
window_padding = { left = 0, right = 0, top = 0, bottom = 0 },
colors = colors,
color_scheme = "Nord (base16)", -- will be overwritten by colors
-- default_prog = {"nu"},
scrollback_lines = 10000,
font = wezterm.font('Iosevka Nerd Font'),
-- add cursive italic font from Victor font for all weights
font_rules = {
{
intensity = 'Bold',
italic = true,
font = wezterm.font {
family = 'VictorMono Nerd Font',
weight = 'Bold',
style = 'Italic',
},
},
{
italic = true,
intensity = 'Half',
font = wezterm.font {
family = 'VictorMono Nerd Font',
weight = 'DemiBold',
style = 'Italic',
},
},
{
italic = true,
intensity = 'Normal',
font = wezterm.font {
family = 'VictorMono Nerd Font',
style = 'Italic',
},
},
},
line_height = 1.0,
leader = { key = 'a', mods = 'CTRL', timeout_milliseconds = 1500 },
keys = maps.keys,
key_tables = maps.key_tables,
mouse_bindings = {
{
event = { Up = { streak = 1, button = 'Left' } },
mods = 'NONE',
action = wezterm.action
.CompleteSelectionOrOpenLinkAtMouseCursor
'ClipboardAndPrimarySelection'
}
}
enable_wayland = true,
hide_tab_bar_if_only_one_tab = true,
use_fancy_tab_bar = false,
tab_bar_at_bottom = true,
window_padding = { left = 0, right = 0, top = 0, bottom = 0 },
colors = colors,
color_scheme = "Nord (base16)", -- will be overwritten by colors
-- default_prog = {"nu"},
scrollback_lines = 10000,
font = wezterm.font("Iosevka Nerd Font"),
-- add cursive italic font from Victor font for all weights
font_rules = {
{
intensity = "Bold",
italic = true,
font = wezterm.font({
family = "VictorMono Nerd Font",
weight = "Bold",
style = "Italic",
}),
},
{
italic = true,
intensity = "Half",
font = wezterm.font({
family = "VictorMono Nerd Font",
weight = "DemiBold",
style = "Italic",
}),
},
{
italic = true,
intensity = "Normal",
font = wezterm.font({
family = "VictorMono Nerd Font",
style = "Italic",
}),
},
},
line_height = 1.0,
leader = { key = "a", mods = "CTRL", timeout_milliseconds = 1500 },
keys = maps.keys,
key_tables = maps.key_tables,
mouse_bindings = {
{
event = { Up = { streak = 1, button = "Left" } },
mods = "NONE",
action = wezterm.action.CompleteSelectionOrOpenLinkAtMouseCursor("ClipboardAndPrimarySelection"),
},
},
}
return settings