From 90cfde370acfe9c852efd26c19c9410c070909fa Mon Sep 17 00:00:00 2001 From: Dinesh Salunke Date: Sat, 30 Sep 2023 11:01:40 +0530 Subject: [PATCH] chore: initial commit --- keymaps.lua | 102 ++++++++++++++++++++++++++++++++++ ssh.lua | 13 +++++ terminal.lua | 51 +++++++++++++++++ update-right-status.lua | 119 ++++++++++++++++++++++++++++++++++++++++ wezterm.lua | 29 ++++++++++ 5 files changed, 314 insertions(+) create mode 100644 keymaps.lua create mode 100644 ssh.lua create mode 100644 terminal.lua create mode 100644 update-right-status.lua create mode 100644 wezterm.lua diff --git a/keymaps.lua b/keymaps.lua new file mode 100644 index 0000000..02bba5a --- /dev/null +++ b/keymaps.lua @@ -0,0 +1,102 @@ +local wezterm = require("wezterm") +local act = wezterm.action +local gui = wezterm.gui + +local M = {} + +local direction_keys = { + Left = "h", + Down = "j", + Up = "k", + Right = "l", + -- reverse lookup + h = "Left", + j = "Down", + k = "Up", + l = "Right", +} + +-- if you are *NOT* lazy-loading smart-splits.nvim (recommended) +local function is_vim(pane) + -- this is set by the plugin, and unset on ExitPre in Neovim + return pane:get_user_vars().IS_NVIM == "true" +end + +local function split_nav(resize_or_move, key) + return { + key = key, + mods = resize_or_move == "resize" and "META" or "CTRL", + action = wezterm.action_callback(function(win, pane) + if is_vim(pane) then + -- pass the keys through to vim/nvim + win:perform_action({ + SendKey = { key = key, mods = resize_or_move == "resize" and "META" or "CTRL" }, + }, pane) + else + if resize_or_move == "resize" then + win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane) + else + win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane) + end + end + end), + } +end + +function M.options(config) + -- + config.leader = { key = "a", mods = "CTRL" } + + config.keys = { + { key = "a", mods = "LEADER|CTRL", action = wezterm.action({ SendString = "\x01" }) }, + { key = "-", mods = "LEADER", action = wezterm.action({ SplitVertical = { domain = "CurrentPaneDomain" } }) }, + { + key = "\\", + mods = "LEADER", + action = wezterm.action({ SplitHorizontal = { domain = "CurrentPaneDomain" } }), + }, + { key = "z", mods = "LEADER", action = "TogglePaneZoomState" }, + { key = "c", mods = "LEADER", action = wezterm.action({ SpawnTab = "CurrentPaneDomain" }) }, + { key = "x", mods = "LEADER", action = wezterm.action.CloseCurrentPane({ confirm = true }) }, + { key = "n", mods = "LEADER", action = wezterm.action.ToggleFullScreen }, + { key = "p", mods = "CTRL|SHIFT", action = wezterm.action.ActivateCommandPalette }, + { key = "c", mods = "CTRL|SHIFT", action = wezterm.action.CopyTo("ClipboardAndPrimarySelection") }, + { key = "v", mods = "CTRL|SHIFT", action = wezterm.action.PasteFrom("Clipboard") }, + -- move between split panes + split_nav("move", "h"), + split_nav("move", "j"), + split_nav("move", "k"), + split_nav("move", "l"), + -- resize panes + split_nav("resize", "h"), + split_nav("resize", "j"), + split_nav("resize", "k"), + { + key = ",", + mods = "LEADER", + action = act.PromptInputLine({ + description = "Enter new name for tab", + action = wezterm.action_callback(function(window, pane, line) + -- line will be `nil` if they hit escape without entering anything + -- An empty string if they just hit enter + -- Or the actual line of text they wrote + if line then + window:active_tab():set_title(line) + end + end), + }), + }, + split_nav("resize", "l"), + } + + for i = 1, 8 do + -- CTRL+ALT + number to activate that tab + table.insert(config.keys, { + key = tostring(i), + mods = "LEADER", + action = wezterm.action.ActivateTab(i - 1), + }) + end +end + +return M diff --git a/ssh.lua b/ssh.lua new file mode 100644 index 0000000..fbec9e6 --- /dev/null +++ b/ssh.lua @@ -0,0 +1,13 @@ +local M = {} + +function M.options(config) + config.ssh_domains = { + { + name = "thob_alpha", + remote_address = "68.183.89.231", + multiplexing = "None", + }, + } +end + +return M diff --git a/terminal.lua b/terminal.lua new file mode 100644 index 0000000..f2280d1 --- /dev/null +++ b/terminal.lua @@ -0,0 +1,51 @@ +local term = require("wezterm") + +local M = {} + +---- Appearance +-- Color pallete +M.colors = { + transparent = "rgba(0,0,0,0)", +} + +function M.options(config) + config.status_update_interval = 1000 + config.color_scheme = "Catppuccin Mocha" + + config.animation_fps = 240 + config.max_fps = 240 + + config.initial_cols = 117 + config.initial_rows = 32 + config.font = term.font({ + family = "JetBrainsMono Nerd Font", + weight = "Medium", + stretch = "Normal", + style = "Normal", + harfbuzz_features = { "calt=1", "clig=1", "liga=1" }, + -- scale = 1.0 + }) + config.font_size = 14 + config.enable_scroll_bar = false + config.inactive_pane_hsb = { saturation = 1.0, brightness = 1.0 } + config.window_padding = { left = "1px", right = "1px", top = "0.1cell", bottom = "0.1cell" } + + ----- Misc + config.adjust_window_size_when_changing_font_size = false + config.audible_bell = "Disabled" + config.exit_behavior = "Close" + config.window_close_confirmation = "NeverPrompt" + config.scrollback_lines = 50000 + config.tab_max_width = 9999 + config.hide_tab_bar_if_only_one_tab = true + config.tab_bar_at_bottom = true + config.use_fancy_tab_bar = false + config.show_new_tab_button_in_tab_bar = false + config.allow_win32_input_mode = true + config.disable_default_key_bindings = true + + config.window_background_opacity = 0.9 + config.macos_window_background_blur = 50 +end + +return M diff --git a/update-right-status.lua b/update-right-status.lua new file mode 100644 index 0000000..1a9b958 --- /dev/null +++ b/update-right-status.lua @@ -0,0 +1,119 @@ +local M = {} + +function M.init(wezterm, terminal) + wezterm.on("update-right-status", function(window, pane) + local cells = {} + local key_mode = window:active_key_table() + local mode = { + ["search_mode"] = "󰜏", + ["copy_mode"] = "", + } + if not key_mode then + table.insert(cells, "") + else + table.insert(cells, mode[key_mode]) + end + -- + local workspace = window:active_workspace() + if workspace == "default" then + workspace = "" + end + table.insert(cells, workspace) + + local cwd_uri = pane:get_current_working_dir() + if cwd_uri then + cwd_uri = cwd_uri:sub(8) + local slash = cwd_uri:find("/") + local cwd = "" + local hostname = "" + if slash then + hostname = cwd_uri:sub(1, slash - 1) + -- Remove the domain name portion of the hostname + local dot = hostname:find("[.]") + if dot then + hostname = hostname:sub(1, dot - 1) + end + -- and extract the cwd from the uri + cwd = cwd_uri:sub(slash) + -- table.insert(cells, cwd) + if hostname == "" then + table.insert(cells, "") + elseif string.find(hostname, "arch") then + table.insert(cells, "") + else + table.insert(cells, "") + end + end + end + local current_time = tonumber(wezterm.strftime("%H")) + -- stylua: ignore + local time = { + [00] = "", + [01] = "", + [02] = "", + [03] = "", + [04] = "", + [05] = "", + [06] = "", + [07] = "", + [08] = "", + [09] = "", + [10] = "󰗲", + [11] = "", + [12] = "", + [13] = "", + [14] = "", + [15] = "", + [16] = "", + [17] = "", + [18] = "", + [19] = "󰗲", + [20] = "", + [21] = "", + [22] = "", + [23] = "", + } + local date = wezterm.strftime("%H:%M:%S %a %b %d ") + local date_time = time[current_time] .. " " .. date + table.insert(cells, date_time) + -- local SEPERATOR = " █" + local SEPERATOR = " " + local pallete = { + "#f7768e", + "#9ece6a", + "#7dcfff", + "#bb9af7", + "#e0af68", + "#7aa2f7", + } + local cols = pane:get_dimensions().cols + local padding = wezterm.pad_right("", (cols / 2) - string.len(date_time) - 2) + local elements = {} + local num_cells = 0 + + -- Translate into elements + local function push(text, is_last) + local cell_no = num_cells + 1 + if is_last then + -- table.insert(elements, text_fg) + table.insert(elements, { Text = padding }) + end + table.insert(elements, { Foreground = { Color = pallete[cell_no] } }) + table.insert(elements, { Background = { Color = terminal.colors.transparent } }) + table.insert(elements, { Text = "" .. text .. "" }) + if not is_last then + table.insert(elements, { Foreground = { Color = terminal.colors.transparent } }) + table.insert(elements, { Background = { Color = terminal.colors.transparent } }) + table.insert(elements, { Text = SEPERATOR }) + end + num_cells = num_cells + 1 + end + + while #cells > 0 do + local cell = table.remove(cells, 1) + push(cell, #cells == 0) + end + window:set_right_status(wezterm.format(elements)) + end) +end +return M diff --git a/wezterm.lua b/wezterm.lua new file mode 100644 index 0000000..7757183 --- /dev/null +++ b/wezterm.lua @@ -0,0 +1,29 @@ +-- Pull in the wezterm API +------------------------------------------------------ +-- Wezterm configuration +------------------------------------------------------ + +local wezterm = require("wezterm") + +local terminal = require("terminal") +local keymaps = require("keymaps") +local ssh = require("ssh") +local update_right_status = require("update-right-status") + +-- This table will hold the configuration. +local config = {} +-- In newer versions of wezterm, use the config_builder which will +-- help provide clearer error messages +if wezterm.config_builder then + config = wezterm.config_builder() +end + +terminal.options(config, wezterm) +keymaps.options(config) +ssh.options(config) +update_right_status.init(wezterm, terminal) + +-- This is where you actually apply your config choices + +-- and finally, return the configuration to wezterm +return config