This commit expands quick select mode so that you can trigger it with distinct sets of patterns (eg: urls on one key assignment, hashes on a different key assignment), different alphabets, and lastly, the option to perform a different action from the default copy action. You can pair this with `action_callback` to run lua code to do something with the selected text. This commit also adds `wezterm.open_with`, a helper function for opening documents/URLs. refs: #846 refs: #1362
61 lines
1.8 KiB
Markdown
61 lines
1.8 KiB
Markdown
# QuickSelectArgs
|
|
|
|
*Since: nightly builds only*
|
|
|
|
Activates [Quick Select Mode](../../../quickselect.md) but with the option
|
|
to override the global configuration.
|
|
|
|
This example shows how to pop up a quick select that is scoped solely to
|
|
a very basic http regex; it will only match those regexes regardless of
|
|
the default or the [quick_select_patterns](../config/quick_select_patterns.md)
|
|
configuration:
|
|
|
|
```lua
|
|
local wezterm = require 'wezterm'
|
|
|
|
return {
|
|
keys = {
|
|
{key="P", mods="CTRL",
|
|
action=wezterm.action{QuickSelectArgs={
|
|
patterns={
|
|
"https?://\\S+"
|
|
},
|
|
}}
|
|
},
|
|
},
|
|
}
|
|
```
|
|
|
|
The `QuickSelectArgs` struct allows for the following fields:
|
|
|
|
* `patterns` - if present, completely overrides the normal set of patterns and uses only the patterns specified
|
|
* `alphabet` - if present, this alphabet is used instead of [quick_select_alphabet](../config/quick_select_alphabet.md)
|
|
* `action` - if present, this key assignment action is performed as if by [window:perform_action](../window/perform_action.md) when an item is selected. The normal clipboard action is NOT performed in this case.
|
|
|
|
Here's an example that shows how to trigger some lua code to operate on the
|
|
quick-selected text, instead of copying it to the clipboard. Here, we open
|
|
the selected URL using the web browser:
|
|
|
|
```lua
|
|
local wezterm = require 'wezterm'
|
|
|
|
return {
|
|
keys = {
|
|
{key="P", mods="CTRL",
|
|
action=wezterm.action{QuickSelectArgs={
|
|
patterns={
|
|
"https?://\\S+"
|
|
},
|
|
action = wezterm.action_callback(function(window, pane)
|
|
local url = window:get_selection_text_for_pane(pane)
|
|
wezterm.log_info("opening: " .. url)
|
|
wezterm.open_with(url)
|
|
end)
|
|
}}
|
|
},
|
|
},
|
|
}
|
|
```
|
|
|
|
See also [wezterm.open_with](../wezterm/open_with.md).
|