diff --git a/config/src/lua.rs b/config/src/lua.rs index d10410f34..f47591ea6 100644 --- a/config/src/lua.rs +++ b/config/src/lua.rs @@ -346,6 +346,12 @@ end )?; wezterm_mod.set("hostname", lua.create_function(hostname)?)?; wezterm_mod.set("action", luahelper::enumctor::Enum::::new())?; + wezterm_mod.set( + "has_action", + lua.create_function(|_lua, name: String| { + Ok(KeyAssignment::variants().contains(&name.as_str())) + })?, + )?; lua.set_named_registry_value(LUA_REGISTRY_USER_CALLBACK_COUNT, 0)?; wezterm_mod.set("action_callback", lua.create_function(action_callback)?)?; diff --git a/docs/changelog.md b/docs/changelog.md index b6ee333c0..8b3006972 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -67,6 +67,8 @@ As features stabilize some brief notes about them will accumulate here. * [pane:get_tty_name()](config/lua/pane/get_tty_name.md) and [PaneInformation.tty_name](config/lua/PaneInformation.md) to reason about the tty name on local unix systems. +* [wezterm.has_action()](config/lua/wezterm/has_action.md) makes it easier to + author a wezterm config that works across different wezterm versions. #3454 #### Fixed * mux: Stale remote window mapping could prevent spawning new tabs in remote domain. #2759 diff --git a/docs/config/lua/wezterm/has_action.md b/docs/config/lua/wezterm/has_action.md new file mode 100644 index 000000000..06b59a339 --- /dev/null +++ b/docs/config/lua/wezterm/has_action.md @@ -0,0 +1,21 @@ +# wezterm.has_action(NAME) + +{{since('nightly')}} + +Returns true if the string *NAME* is a valid key assignment action variant +that can be used with [wezterm.action](action.md). + +This is useful when you want to use a wezterm configuration across multiple +different versions of wezterm. + +```lua +if wezterm.has_action 'PromptInputLine' then + table.insert(config.keys, { + key = 'p', + mods = 'LEADER', + action = wezterm.action.PromptInputLine { + -- other parameters here + }, + }) +end +```