Files
LLeMbas-TTY/docs/config/lua/wezterm.url/encode.md
T
mgpinf a0d411761d lua: Add wezterm.url.encode function to percent encode string (#7131)
This is helpful to encode a string to pass it as query string.
2026-11-20 04:19:20 +01:00

48 lines
1.0 KiB
Markdown

# `wezterm.url.encode(string)`
{{since('nightly')}}
Returns the percent encoded version of the provided string.
## Example: opening a line in browser with a search engine
```lua
local wezterm = require 'wezterm'
local act = wezterm.action
local config = wezterm.config_builder()
local SEARCH_ENGINES = {
['Google'] = 'https://www.google.com/search?q=',
['Youtube'] = 'https://www.youtube.com/results?search_query=',
}
local function get_action_to_search(search_engine)
return act.PromptInputLine {
description = 'Search with ' .. search_engine,
action = wezterm.action_callback(function(_win, _pane, line)
if line and #line > 0 then
local final_url = SEARCH_ENGINES[search_engine]
.. wezterm.url.encode(line)
wezterm.open_with(final_url)
end
end),
}
end
config.keys = {
{
key = 'g',
mods = 'CTRL',
action = get_action_to_search 'Google',
},
{
key = 'y',
mods = 'CTRL',
action = get_action_to_search 'Youtube',
},
}
return config
```