Advertisement
Guest User

Wezterm Config Windows (WSL2)

a guest
May 6th, 2024
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.55 KB | None | 0 0
  1. local wezterm = require 'wezterm'
  2. local symbols = require("wezterm").nerdfonts
  3.  
  4. local colors = { -- Dracula+
  5.   foreground = "#f8f8f2",
  6.   background = "#212121",
  7.  
  8.   cursor_bg = "#ECEFF4",
  9.   cursor_fg = "#0E1415",
  10.   cursor_border = "#f8f8f2",
  11.  
  12.   selection_fg = "none",
  13.   selection_bg = "rgba(68,71,90,0.5)",
  14.  
  15.   scrollbar_thumb = "#44475a",
  16.   split = "#6272a4",
  17.  
  18.   ansi = { "#21222C", "#FF5555", "#50FA7B", "#FFCB6B", "#BD93F9", "#FF79C6", "#8BE9FD", "#BBBBBB" },
  19.   brights = { "#545454", "#FF6E6E", "#69FF94", "#F1FA8C", "#D6ACFF", "#FF92DF", "#A4FFFF", "#FFFFFF" },
  20.  
  21.   indexed = {
  22.     -- might need to change this
  23.     [16] = "#FFFFFF",
  24.     [17] = "#BBBBBB",
  25.   }
  26. }
  27.  
  28.  
  29. -- Setting the tabs
  30. local tabs = {}
  31.  
  32. -- Strips basename from a file path (E.g.: /cat/dog becomes dog) and
  33. -- strip the executable extension
  34. local function stripbase(path)
  35.   local new_path = string.gsub(path, "(.*[/\\])(.*)", "%2")
  36.   return new_path:gsub("%.exe$", "")
  37. end
  38.  
  39. -- Tab separator icons
  40. local FIRST_TAB_LEFT_SIDE = "█"
  41. local TAB_LEFT_SIDE = symbols.ple_left_half_circle_thick
  42. local TAB_RIGHT_SIDE = symbols.ple_right_half_circle_thick
  43.  
  44. -- Running process icons
  45. local CMD_ICON = symbols.cod_terminal_cmd
  46. local PS_ICON = symbols.cod_terminal_powershell
  47. local BASH_ICON = symbols.cod_terminal_bash
  48. local WSL_ICON = symbols.cod_terminal_linux
  49. local HOURGLASS_ICON = symbols.fa_hourglass_half
  50. local NVIM_ICON = symbols.custom_vim
  51.  
  52. -- Default colors
  53. local BACKGROUND_COLOR = colors.background
  54. local FOREGROUND_COLOR = colors.foreground
  55. local EDGE_COLOR = colors.background
  56. local DIM_COLOR = colors.background
  57.  
  58. function tabs.setup()
  59.   -- Decorate the tab bar with icons based on the running shell/application and its state
  60.   wezterm.on("format-tab-title", function(tab, _, _, _, hover, max_width)
  61.     if tab.is_active then
  62.       BACKGROUND_COLOR = colors.ansi[5]
  63.       FOREGROUND_COLOR = colors.ansi[1]
  64.     elseif hover then
  65.       BACKGROUND_COLOR = colors.brights[4]
  66.       FOREGROUND_COLOR = colors.ansi[1]
  67.     else
  68.       BACKGROUND_COLOR = colors.selection_bg
  69.       FOREGROUND_COLOR = colors.selection_fg
  70.     end
  71.  
  72.     local edge_foreground = BACKGROUND_COLOR
  73.     local process_name = tab.active_pane.foreground_process_name
  74.     local exec_name = stripbase(process_name)
  75.     local title_with_icon = ""
  76.  
  77.     -- Select an appropriate icon
  78.     if exec_name == "pwsh" then
  79.       title_with_icon = PS_ICON .. " PS"
  80.     elseif exec_name == "cmd" then
  81.       title_with_icon = CMD_ICON .. " CMD"
  82.     elseif exec_name == "wsl" or exec_name == "wslhost" then
  83.       title_with_icon = WSL_ICON .. " WSL"
  84.     elseif exec_name == "bash" then
  85.       title_with_icon = BASH_ICON .. " BASH"
  86.     elseif exec_name == "nvim" then
  87.       title_with_icon = NVIM_ICON .. " NVIM"
  88.     else
  89.       title_with_icon = HOURGLASS_ICON .. " " .. exec_name
  90.     end
  91.  
  92.     -- Identify tab number with a numeral
  93.     local id = string.format("%s", tab.tab_index + 1)
  94.  
  95.     -- Trim long titles
  96.     local title = " " .. wezterm.truncate_right(title_with_icon, max_width - 5) .. " "
  97.  
  98.     return {
  99.       { Attribute = { Intensity = "Bold" } },
  100.       { Background = { Color = EDGE_COLOR } },
  101.       { Foreground = { Color = edge_foreground } },
  102.       { Text = tab.tab_index == 0 and FIRST_TAB_LEFT_SIDE or TAB_LEFT_SIDE },
  103.       { Background = { Color = BACKGROUND_COLOR } },
  104.       { Foreground = { Color = FOREGROUND_COLOR } },
  105.       { Text = id },
  106.       { Text = title },
  107.       { Foreground = { Color = DIM_COLOR } },
  108.       { Background = { Color = EDGE_COLOR } },
  109.       { Foreground = { Color = edge_foreground } },
  110.       { Text = TAB_RIGHT_SIDE },
  111.       { Attribute = { Intensity = "Normal" } },
  112.     }
  113.   end)
  114. end
  115.  
  116. return {
  117.   -- Font settings
  118.   font = wezterm.font("JetBrainsMono Nerd Font"),
  119.   font_size = 11,
  120.   freetype_interpreter_version = 40,
  121.   unicode_version = 14,
  122.   harfbuzz_features = { "calt=1", "liga=1", "clig=1", "dlig=1" },
  123.   warn_about_missing_glyphs = false,
  124.  
  125.   -- reason: https://github.com/DerekSauer/wezterm-config/blob/1529c3157c13c508005547e9a8513ab688361b8a/wezterm.lua#L22
  126.   -- front_end = "OpenGL",
  127.  
  128.   -- Window size and theming
  129.   colors = {
  130.     foreground = colors.foreground,
  131.     background = colors.background,
  132.  
  133.     cursor_bg = colors.cursor_bg,
  134.     cursor_fg = colors.cursor_fg,
  135.     cursor_border = colors.cursor_border,
  136.  
  137.     selection_fg = colors.selection_fg,
  138.     selection_bg = colors.selection_bg,
  139.  
  140.     scrollbar_thumb = colors.scrollbar_thumb,
  141.     split = colors.split,
  142.  
  143.     ansi = colors.ansi,
  144.     brights = colors.brights,
  145.     indexed = colors.indexed,
  146.  
  147.     tab_bar = {
  148.       background = colors.background,
  149.       new_tab = {
  150.         bg_color = colors.background,
  151.         fg_color = colors.foreground,
  152.         intensity = "Bold",
  153.       },
  154.       new_tab_hover = {
  155.         bg_color = colors.background,
  156.         fg_color = colors.foreground,
  157.         italic = true,
  158.         intensity = "Bold",
  159.       },
  160.     },
  161.  
  162.   },
  163.   initial_cols = 120,
  164.   initial_rows = 32,
  165.   audible_bell = "Disabled",
  166.   scrollback_lines = 1000,
  167.   force_reverse_video_cursor = true,
  168.   enable_scroll_bar = false,
  169.   window_background_opacity = 1.0,
  170.   text_background_opacity = 1.0,
  171.   window_padding = {
  172.     left = 0,
  173.     right = 0,
  174.     top = 0,
  175.     bottom = 0,
  176.   },
  177.  
  178.   default_cursor_style = "BlinkingUnderline",
  179.   default_prog = { 'powershell.exe' },
  180.  
  181.   -- Tabbar
  182.   -- hide_tab_bar_if_only_one_tab = true,
  183.   use_fancy_tab_bar = false,
  184.   tab_max_width = 60,
  185.  
  186.   -- Window
  187.   window_decorations = "INTEGRATED_BUTTONS | RESIZE",
  188.   adjust_window_size_when_changing_font_size = false,
  189.   integrated_title_button_style = "Windows",
  190.   integrated_title_button_color = "auto",
  191.   integrated_title_button_alignment = "Right",
  192.   window_close_confirmation = 'AlwaysPrompt',
  193.  
  194.   -- Keys
  195.   send_composed_key_when_left_alt_is_pressed = false,
  196.   send_composed_key_when_right_alt_is_pressed = false,
  197.  
  198.   -- Visual bell, flare the cursor
  199.   visual_bell = {
  200.     fade_in_duration_ms = 75,
  201.     fade_out_duration_ms = 75,
  202.     target = "CursorColor",
  203.   },
  204.  
  205.   tabs.setup(),
  206.  
  207.   hyperlink_rules = {
  208.     { -- Linkify things that look like URLs
  209.       regex = "\\b\\w+://(?:[\\w.-]+)\\.[a-z]{2,15}\\S*\\b",
  210.       format = "$0",
  211.     },
  212.     { -- match the URL with a PORT such 'http://localhost:3000/index.html'
  213.       regex = "\\b\\w+://(?:[\\w.-]+):\\d+\\S*\\b",
  214.       format = "$0",
  215.     },
  216.     { -- linkify email addresses
  217.       regex = "\\b\\w+@[\\w-]+(\\.[\\w-]+)+\\b",
  218.       format = "mailto:$0",
  219.     },
  220.     { -- file:// URI
  221.       regex = "\\bfile://\\S*\\b",
  222.       format = "$0",
  223.     },
  224.   },
  225. }
  226.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement