diff --git a/wezterm/.wezterm.lua b/wezterm/.wezterm.lua new file mode 100644 index 0000000..44011c0 --- /dev/null +++ b/wezterm/.wezterm.lua @@ -0,0 +1,370 @@ +local wezterm = require 'wezterm' + +local workspace_switcher = wezterm.plugin.require("https://github.com/MLFlexer/smart_workspace_switcher.wezterm") +local tabline = wezterm.plugin.require("https://github.com/michaelbrusegard/tabline.wez") +-- local resurrect = wezterm.plugin.require("https://github.com/MLFlexer/resurrect.wezterm") + +local function strsplit(inputstr, sep) + if sep == nil then + sep = "%s" + end + local t = {} + for str in string.gmatch(inputstr, "([^"..sep.."]+)") do + table.insert(t, str) + end + return t +end + +local config = wezterm.config_builder() +config.color_scheme = 'Ayu Dark (Gogh)' +-- config.color_scheme = 'Ayu Mirage' + +-- config.leader = { key = 'Space', mods = 'CTRL', timeout_milliseconds = 1000 } +config.keys = { + -- { + -- key = 'x', + -- mods = 'CTRL', + -- action = wezterm.action.CopyTo 'Clipboard', + -- }, + + { key = 'd', mods = 'LEADER', action = wezterm.action.QuitApplication }, + + { + key = "s", + mods = "LEADER", + action = workspace_switcher.switch_workspace(), + }, + { key = 'L', mods = 'CTRL', action = wezterm.action.ShowDebugOverlay }, + { + key = "n", + mods = "LEADER", + action = wezterm.action.PromptInputLine { + description = wezterm.format { + { Attribute = { Intensity = 'Bold' } }, + { Foreground = { AnsiColor = 'Fuchsia' } }, + { Text = 'Enter name for new workspace' }, + }, + action = wezterm.action_callback(function(window, pane, line) + if line then + window:perform_action( + wezterm.action.SwitchToWorkspace { + name = line, + }, + pane + ) + end + end), + }, + }, + { + key = "r", + mods = "LEADER", + action = wezterm.action.PromptInputLine { + description = wezterm.format { + { Attribute = { Intensity = 'Bold' } }, + { Foreground = { AnsiColor = 'Fuchsia' } }, + { Text = 'Rename workspace' }, + }, + action = wezterm.action_callback(function(window, pane, line) + if line then + wezterm.run_child_process { 'wezterm', 'cli', 'rename-workspace', line} + end + end), + }, + }, + { + key = "t", + mods = "LEADER", + action = wezterm.action.PromptInputLine { + description = wezterm.format { + { Attribute = { Intensity = 'Bold' } }, + { Foreground = { AnsiColor = 'Fuchsia' } }, + { Text = 'Rename tab' }, + }, + action = wezterm.action_callback(function(window, pane, line) + if line then + wezterm.run_child_process { 'wezterm', 'cli', 'set-tab-title', line} + end + end), + }, + }, + -- { + -- key = "l", + -- mods = "LEADER", + -- action = wezterm.action_callback(function(win, pane) + -- resurrect.fuzzy_load(win, pane, function(id, label) + -- local type = string.match(id, "^([^/]+)") -- match before '/' + -- id = string.match(id, "([^/]+)$") -- match after '/' + -- id = string.match(id, "(.+)%..+$") -- remove file extention + -- local opts = { + -- relative = true, + -- restore_text = true, + -- on_pane_restore = resurrect.tab_state.default_on_pane_restore, + -- } + -- if type == "workspace" then + -- local state = resurrect.load_state(id, "workspace") + -- resurrect.workspace_state.restore_workspace(state, opts) + -- elseif type == "window" then + -- local state = resurrect.load_state(id, "window") + -- resurrect.window_state.restore_window(pane:window(), state, opts) + -- elseif type == "tab" then + -- local state = resurrect.load_state(id, "tab") + -- resurrect.tab_state.restore_tab(pane:tab(), state, opts) + -- end + -- end) + -- end), + -- }, + -- { + -- key = "w", + -- mods = "LEADER", + -- action = wezterm.action_callback(function(win, pane) + -- resurrect.save_state(resurrect.workspace_state.get_workspace_state()) + -- end), + -- }, +} + +local tl_config = require('tabline.config') +-- local scheme = tl_config.colors.scheme + +local fetch_cache = { + ['playing'] = { + text = nil, + last = 0, + secs = 5, + }, + ['weather'] = { + text = nil, + last = 0, + secs = 600, + }, +} + +local function currently_playing() + if fetch_cache.playing.text == nil or os.clock() - fetch_cache.playing.last > fetch_cache.playing.secs then + local success, stdout, _ = wezterm.run_child_process {'python', 'C:/Users/robea/Dev/scripts/currently_playing.py'} + if success then + fetch_cache.playing.text = stdout .. ' ' + else + fetch_cache.playing.text = '' + end + fetch_cache.playing.last = os.clock() + end + return fetch_cache.playing.text +end + +local function weather() + if fetch_cache.weather.text == nil or os.clock() - fetch_cache.weather.last > fetch_cache.weather.secs then + local success, stdout, _ = wezterm.run_child_process {'curl', 'wttr.in?format=%c%t'} + if success then + local parts = strsplit(stdout) + fetch_cache.weather.text = string.format(' %s%s ', parts[1], parts[2]) + else + fetch_cache.weather.text = '' + end + fetch_cache.weather.last = os.clock() + end + return fetch_cache.weather.text +end + +local function datetime() + -- local time_format = '%H:%M %d/%m' + local time_format = '%H:%M' + local time_icon = wezterm.nerdfonts['weather_time_'..tonumber(os.date('%I'))] + return string.format(' %s %s ', time_icon, os.date(time_format)) +end + +local function battery() + local bat = '' + for _, b in ipairs(wezterm.battery_info()) do + local battery_icon_prefix = 'md_battery_' + if b.state == 'Charging' then + battery_icon_prefix = battery_icon_prefix..'charging_' + end + local charge_icon = wezterm.nerdfonts[battery_icon_prefix..math.floor(b.state_of_charge * 10)*10] + if charge_icon == nil then + charge_icon = wezterm.nerdfonts.md_battery_alert_variant_outline + end + bat = string.format(' %s %.0f%%', charge_icon, b.state_of_charge*100) + end + return bat +end + +local colors = { + bg = '#0B0E14', + fg = '#bbc2cf', + fg_idle = '#8A9199', + accent = '#FFAA33', + ui = '#8A9199', + mir_accent = '#FFCC66', + mir_bg = '#1F2430', + mir_fg = '#CCCAC2', + mir_ui = '#707A8C', + yellow = '#ECBE7B', + cyan = '#008080', + darkblue = '#081633', + green = '#98be65', + orange = '#FF8800', + violet = '#a9a1e1', + magenta = '#c678dd', + blue = '#51afef', + red = '#ec5f67', +} + +tabline.setup{ + options = { + theme = 'Ayu Dark (Gogh)', + tab_separators = { + left = '', + right = '', + -- left = wezterm.nerdfonts.pl_left_hard_divider, + -- right = wezterm.nerdfonts.pl_right_hard_divider, + }, + component_separators = { + -- left = '', + -- right = '', + left = wezterm.nerdfonts.pl_left_soft_divider, + right = wezterm.nerdfonts.pl_right_soft_divider, + }, + section_separators = { + left = wezterm.nerdfonts.pl_left_hard_divider, + right = wezterm.nerdfonts.pl_right_hard_divider, + -- right = wezterm.nerdfonts.pl_right_soft_divider, + }, + color_overrides = { + normal_mode = { + a = { fg = colors.mir_bg, bg = colors.mir_accent }, + -- b = { fg = colors.fg, bg = colors.bg }, + x = { fg = colors.mir_ui}, + y = { fg = colors.mir_accent, bg = colors.mir_bg }, + z = { fg = colors.mir_bg, bg = colors.mir_acent }, + }, + tab = { + active = { fg = colors.mir_accent, bg = colors.mir_bg }, + inactive = { fg = colors.mir_ui, bg = colors.bg }, + }, + }, + }, + sections = { + tabline_a = { { 'workspace', padding = {left = 1, right = 1}}}, + tabline_b = {}, + tabline_c = { ' ' }, + -- tab_active = { + -- 'index', + -- { + -- 'process', + -- padding = { left = 0, right = 1 }, + -- }, + -- }, + -- tab_inactive = { + -- 'index', + -- { + -- 'process', + -- padding = { left = 0, right = 1 }, + -- }, + -- }, + -- tab_inactive = { 'index', { 'process', padding = { left = 0, right = 1 } } }, + tab_active = { {Attribute = {Intensity = "Bold"}}, 'index' }, + tab_inactive = { 'index' }, + tabline_x = { + -- currently_playing, + }, + tabline_y = { + weather, + datetime, + }, + tabline_z = { + battery, + -- { + -- 'hostname', + -- }, + }, + }, + extensions = { + 'smart_workspace_switcher', + -- 'resurrect', + } +} + +tabline.apply_to_config(config) +-- workspace_switcher.apply_to_config(config, {}) + +-- config.default_prog = {'powershell.exe', '-NoExit', '-Command', '&{Import-Module "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll"; Enter-VsDevShell 0fa0d336 -SkipAutomaticLocation -DevCmdArguments "-arch=x64 -host_arch=x64"}'} +-- config.default_prog = {'nu.exe'} +-- config.default_cwd = 'D:\\Dev' +-- config.default_cwd = '~/Dev' +config.default_prog = {'/usr/bin/nu'} + +config.default_workspace = '~' + +config.default_cursor_style = 'BlinkingBlock' +config.animation_fps = 24 +-- config.cursor_blink_ease_in = 'Constant' +-- config.cursor_blink_ease_out = 'Constant' +config.cursor_blink_rate = 600; + +config.window_padding = { + left = 0, + right = 0, + top = 0, + bottom = 0, +} + +-- config.window_background_opacity = 0.5 +-- config.win32_system_backdrop = 'Acrylic' + +config.font = wezterm.font 'Fira Code' + +-- config.window_frame = { +-- font = require('wezterm').font 'Roboto', +-- font_size = 10, +-- border_left_width = '0.5cell', +-- border_right_width = '0.5cell', +-- border_bottom_height = '0.25cell', +-- border_top_height = '0.25cell', +-- border_left_color = 'purple', +-- border_right_color = 'purple', +-- border_bottom_color = 'purple', +-- border_top_color = 'purple', +-- } + +-- config.window_decorations="INTEGRATED_BUTTONS|RESIZE" +-- config.window_decorations="RESIZE" +config.window_decorations="TITLE | RESIZE" +config.use_fancy_tab_bar=false +config.tab_bar_at_bottom=true +config.show_tabs_in_tab_bar=true +config.hide_tab_bar_if_only_one_tab=false + +config.bidi_enabled = true +config.enable_kitty_graphics = true + +-- config.unix_domains = { +-- { name = 'unix' }, +-- } +-- config.default_gui_startup_args = { 'connect', 'unix' } + +-- -- loads the state whenever I create a new workspace +-- wezterm.on("smart_workspace_switcher.workspace_switcher.created", function(window, _, label) +-- local workspace_state = resurrect.workspace_state +-- +-- workspace_state.restore_workspace(resurrect.load_state(label, "workspace"), { +-- window = window, +-- relative = true, +-- restore_text = true, +-- on_pane_restore = resurrect.tab_state.default_on_pane_restore, +-- }) +-- end) + +-- Saves the state whenever I select a workspace +-- wezterm.on("smart_workspace_switcher.workspace_switcher.selected", function(window, path, label) +-- local workspace_state = resurrect.workspace_state +-- resurrect.save_state(workspace_state.get_workspace_state()) +-- end) + +-- wezterm.on("gui-startup", function() +-- local tab, pane, window = wezterm.mux.spawn_window{} +-- -- window:gui_window():maximize() +-- window:gui_window():toggle_fullscreen() +-- end) + +return config