diff --git a/config/src/lua.rs b/config/src/lua.rs index d296a8497..c90e1d1c2 100644 --- a/config/src/lua.rs +++ b/config/src/lua.rs @@ -37,9 +37,11 @@ use termwiz::surface::change::Change; /// /// In addition to this, the lua standard library, except for /// the `debug` module, is also available to the script. -pub fn make_lua_context(config_dir: &Path) -> anyhow::Result { +pub fn make_lua_context(config_file: &Path) -> anyhow::Result { let lua = Lua::new(); + let config_dir = config_file.parent().unwrap_or_else(|| Path::new("/")); + { let globals = lua.globals(); // This table will be the `wezterm` module in the script @@ -70,6 +72,12 @@ pub fn make_lua_context(config_dir: &Path) -> anyhow::Result { } } + wezterm_mod.set( + "config_file", + config_file + .to_str() + .ok_or_else(|| anyhow!("config file path is not UTF-8"))?, + )?; wezterm_mod.set( "config_dir", config_dir @@ -650,7 +658,7 @@ mod test { .filter_level(log::LevelFilter::Trace) .try_init(); - let lua = make_lua_context(&std::env::current_dir()?)?; + let lua = make_lua_context(Path::new("testing"))?; let total = Arc::new(Mutex::new(0)); diff --git a/docs/changelog.md b/docs/changelog.md index 391ac1516..f50e4fc3c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -44,6 +44,8 @@ brief notes about them may accumulate here. * Fixed: macOS: wezterm-gui could linger in the background until the mouse moves after all tabs/panes have closed * Fixed: when using [line_height](config/lua/config/line_height.md), wezterm now vertically centers the cell rather than padding only the top [#582](https://github.com/wez/wezterm/issues/582) * Fixed: macOS: in US layouts, `SUPER+SHIFT+[` was incorrectly recognized as `SUPER+SHIFT+{` instead of `SUPER+{` [#601](https://github.com/wez/wezterm/issues/601) +* Fixed: [wezterm.config_dir](config/lua/wezterm/config_dir.md) was returning the config file path instead of the directory! +* New: [wezterm.config_file](config/lua/wezterm/config_file.md) which returns the config file path ### 20210314-114017-04b7cedd diff --git a/docs/config/lua/wezterm/config_file.md b/docs/config/lua/wezterm/config_file.md new file mode 100644 index 000000000..44e5d4cf1 --- /dev/null +++ b/docs/config/lua/wezterm/config_file.md @@ -0,0 +1,13 @@ +# `wezterm.config_file` + +*Since: nightly builds only* + +This constant is set to the path to the `wezterm.lua` that is in use. + +```lua +local wezterm = require 'wezterm'; +wezterm.log_info("Config file " .. wezterm.config_file) +``` + + +