A library of common utility functions for WezTerm plugin developers.
This library provides commonly used functionality for WezTerm plugin development, reducing duplication of code across multiple plugins. The library includes:
- File I/O operations
- String manipulation
- Table operations
- WezTerm-specific utilities
- Cross-platform path handling
Add to your WezTerm configuration:
local lib = wezterm.plugin.require("https://github.com/chrisgve/lib.wezterm")
-- Example: Using the hash function
local key = lib.string.hash("my-string")
-- Example: Reading a file
local success, content = lib.file_io.read_file("/path/to/file")
if success then
-- Use content
end
-- Example: Get current window width
local width = lib.wezterm.get_current_window_width()
string.hash(str)
- Compute a hash from a string using the DJB2 algorithmstring.array_hash(arr)
- Generate a hash from an arraystring.strip_format_esc_seq(str)
- Remove formatting escape sequencesstring.replace_center(str, len, pad)
- Replace the center of a stringstring.utf8len(str)
- Get the length of a UTF-8 string
All string functions can be used with both regular and sugar notation:
-- Regular syntax
local hash = string.hash("test")
-- Sugar syntax
local hash = "test":hash()
file_io.execute(cmd)
- Execute a command and return its stdoutfile_io.ensure_folder_exists(path)
- Create a folder if it doesn't existfile_io.write_file(file_path, str)
- Write a string to a filefile_io.read_file(file_path)
- Read a file's contents
table.deepcopy(original)
- Create a deep copy of a tabletable.tbl_deep_extend(behavior, ...)
- Merge tables with different behaviors
- Platform detection:
utils.is_windows
,utils.is_mac
- Path separator:
utils.separator
wezterm.get_current_window_size()
- Get current window dimensionswezterm.get_current_window_width()
- Get current window width
The library includes a comprehensive test suite to ensure functionality works as expected.
cd lib.wezterm
./tests/run_local.sh
See tests/README.md for more details on testing.
Contributions are welcome! Please add tests for any new functionality.
MIT