Skip to content

Commit

Permalink
config: fix wezterm.config_dir, add wezterm.config_file
Browse files Browse the repository at this point in the history
  • Loading branch information
wez committed Apr 4, 2021
1 parent 7a17ae8 commit b63a949
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions config/src/lua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Lua> {
pub fn make_lua_context(config_file: &Path) -> anyhow::Result<Lua> {
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
Expand Down Expand Up @@ -70,6 +72,12 @@ pub fn make_lua_context(config_dir: &Path) -> anyhow::Result<Lua> {
}
}

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
Expand Down Expand Up @@ -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));

Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions docs/config/lua/wezterm/config_file.md
Original file line number Diff line number Diff line change
@@ -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)
```



0 comments on commit b63a949

Please sign in to comment.