Crate zsh_module
source ·Expand description
Zsh Module
This is a high level crate that allows you to define your own zsh module.
Getting started
To get started, first, you need to create library, not an executable. Then, change your crate
type to "cdylib" on your Cargo.toml:
[lib]
crate-type = ["cdylib"]
Boilerplate
On your lib.rs, you need to put a export_module! macro call, alongside a setup function
(can be called whatever you want):
use zsh_module::{ Module, ModuleBuilder }
zsh_module::export_module!(setup);
fn setup() -> Result<Module, ()> {
todo!()
}Defining Actions
The main point part of crating a module is implementing Actions. Here’s an example module:
use zsh_module::{ Module, ModuleBuilder, Actions, Result }
zsh_module::export_module!(setup);
struct Greeter;
impl Actions for Greeter {
fn boot(mut &self) -> Result<()> {
println!("Hello, everyone!");
Ok(())
}
fn cleanup(&mut self) -> Result<()> {
println!("Bye, everyone!");
Ok(())
}
}
fn setup() -> Result<Module> {
let module = ModuleBuilder::new(Greeter)
.build();
Ok(module)
}Installing
When your module is ready, copy your shared library to your distribution’s zsh module folder and name it whatever you want, the only requirement is that it ends with your platforms’s dynamic loadable library extension.
On my machine, the zsh module folder is /usr/lib/zsh/<zsh-version>/zsh/.
If everything went fine, you can load it in zsh using the following command:
zmodload zsh/<module-name>
That is it!
Modules
Macros
setup function to be called when the module needs to be set up.println!Structs
ModuleBuilderModule