diff --git a/docs/config/lua/config/cell_widths.md b/docs/config/lua/config/cell_widths.md index d2482f213..2d47bd4bb 100644 --- a/docs/config/lua/config/cell_widths.md +++ b/docs/config/lua/config/cell_widths.md @@ -26,8 +26,8 @@ treats these character widths as full-width: ```lua config.cell_widths = { - {first = 0xe000, last = 0xf8ff, width = 2}, - {first = 0xf0000, last = 0xf1fff, width = 2}, + { first = 0xe000, last = 0xf8ff, width = 2 }, + { first = 0xf0000, last = 0xf1fff, width = 2 }, } ``` diff --git a/docs/recipes/hyperlinks.md b/docs/recipes/hyperlinks.md index 704d87b12..505073e48 100644 --- a/docs/recipes/hyperlinks.md +++ b/docs/recipes/hyperlinks.md @@ -25,15 +25,18 @@ With this snippet, you can: - Other hyperlinks like URLs remain unchanged and follow WezTerm's default behavior ```lua -local wezterm = require("wezterm") +local wezterm = require 'wezterm' local act = wezterm.action local config = wezterm.config_builder() local function is_shell(foreground_process_name) local shell_names = { 'bash', 'zsh', 'fish', 'sh', 'ksh', 'dash' } - local process = string.match(foreground_process_name, "[^/\\]+$") or foreground_process_name + local process = string.match(foreground_process_name, '[^/\\]+$') + or foreground_process_name for _, shell in ipairs(shell_names) do - if process == shell then return true end + if process == shell then + return true + end end return false end @@ -41,33 +44,53 @@ end wezterm.on('open-uri', function(window, pane, uri) local editor = 'nvim' - if uri:find('^file:') == 1 and not pane:is_alt_screen_active() then + if uri:find '^file:' == 1 and not pane:is_alt_screen_active() then -- We're processing an hyperlink and the uri format should be: file://[HOSTNAME]/PATH[#linenr] -- Also the pane is not in an alternate screen (an editor, less, etc) local url = wezterm.url.parse(uri) if is_shell(pane:get_foreground_process_name()) then -- A shell has been detected. Wezterm can check the file type directly -- figure out what kind of file we're dealing with - local success, stdout, _ = wezterm.run_child_process({ 'file', '--brief', '--mime-type', url.file_path }) + local success, stdout, _ = wezterm.run_child_process { + 'file', + '--brief', + '--mime-type', + url.file_path, + } if success then - if stdout:find('directory') then - pane:send_text(wezterm.shell_join_args({ 'cd', url.file_path }) .. '\r') - pane:send_text(wezterm.shell_join_args({ 'ls', '-a', '-p', '--group-directories-first' }) .. '\r') + if stdout:find 'directory' then + pane:send_text( + wezterm.shell_join_args { 'cd', url.file_path } .. '\r' + ) + pane:send_text(wezterm.shell_join_args { + 'ls', + '-a', + '-p', + '--group-directories-first', + } .. '\r') return false end - if stdout:find('text') then + if stdout:find 'text' then if url.fragment then - pane:send_text(wezterm.shell_join_args({ editor, '+' .. url.fragment, url.file_path }) .. '\r') + pane:send_text(wezterm.shell_join_args { + editor, + '+' .. url.fragment, + url.file_path, + } .. '\r') else - pane:send_text(wezterm.shell_join_args({ editor, url.file_path }) .. '\r') + pane:send_text( + wezterm.shell_join_args { editor, url.file_path } .. '\r' + ) end return false end end else -- No shell detected, we're probably connected with SSH, use fallback command - local edit_cmd = url.fragment and editor .. ' +' .. url.fragment .. ' "$_f"' or editor .. ' "$_f"' + local edit_cmd = url.fragment + and editor .. ' +' .. url.fragment .. ' "$_f"' + or editor .. ' "$_f"' local cmd = '_f="' .. url.file_path .. '"; { test -d "$_f" && { cd "$_f" ; ls -a -p --hyperlink --group-directories-first; }; } ' @@ -95,17 +118,17 @@ For example, to require holding `CTRL` before opening a hyperlink, use the follo ```lua config.mouse_bindings = { - { - event = { Up = { streak = 1, button = "Left" } }, - mods = "CTRL", - action = act.OpenLinkAtMouseCursor, - }, - -- Disable the 'Down' event of CTRL-Click to avoid weird program behaviors - { - event = { Down = { streak = 1, button = "Left" } }, - mods = "CTRL", - action = act.Nop, - }, + { + event = { Up = { streak = 1, button = 'Left' } }, + mods = 'CTRL', + action = act.OpenLinkAtMouseCursor, + }, + -- Disable the 'Down' event of CTRL-Click to avoid weird program behaviors + { + event = { Down = { streak = 1, button = 'Left' } }, + mods = 'CTRL', + action = act.Nop, + }, } ```